牛客SQL练习第8题

题目描述

找出所有员工当前(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`));

解答:

去重可以使用distinct去重以及group by分组去重(前面的第2题也有去重)

select distinct salary 
from salaries
where to_date="9999-01-01"
order by salary desc
select salary
from salaries
where to_date="9999-01-01"
group by salary
order by salary desc
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页