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;