(秋招SQL实战 : 8.找出所有员工当前薪水salary情况
题目描述:
找出所有员工当前(to_date='9999-01-01')具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示
CREATE TABLE salaries
(
emp_no
int(11) NOT NULL,
salary
int(11) NOT NULL,
from_date
date NOT NULL,
to_date
date NOT NULL,
PRIMARY KEY (emp_no
,from_date
));
输入描述:
无
输出描述:
emp_no |
---|
salary |
94692 |
94409 |
88958 |
88070 |
74057 |
72527 |
59755 |
题目解析:
解法:
select salary from salaries
where to_date = '9999-01-01'
group by salary
order by salary desc;
注:
distinct和group by:
要去重的列数据种类很多时,group by更快
要去重的列数据种类很少时,distinct更快