Find out all employees ' current (to_date= ' 9999-01-01 ') specific salary salary situation, show only once for the same salary, and display in reverse order

Source: Internet
Author: User

Topic address
Topic Description

Find out all employees ' current (to_date= ' 9999-01-01 ') specific salary salary situation, show only once for the same salary, and display in reverse order

CREATE TABLE ' salaries ' (
' emp_no ' int (one) not null,
' salary ' int (one) not null,
' from_date ' date not null,
 
   ' to_date ' date not NULL,
PRIMARY KEY (' emp_no ', ' from_date '));
 

Solution 1

Select distinct salary from 
salaries 
where to_date= ' 9999-01-01 ' ORDER by 
salary desc;

Solution 2

Select salary from 
salaries  
where to_date= ' 9999-01-01 ' GROUP by salary order by salary 
desc;

Attention

For Distinct,groupby performance. When the volume of data is very large, such as 300W of duplicate data in 10 million, the efficiency of the distinct is slightly better than group by; For a relatively small amount of data, such as 10 million of 10,000, the performance of the groupby is much better than the distnct.

MySQL get current time: Now ()

Select distinct salary from 
salaries 
where To_date>=now () Order by 
salary desc;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.