找出所有员工当前(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`));
解析:考察分组操作,这里有两种做法
使用group by:注意这里的order by 必须放在group by后面,不然会报错。
select salary
from salaries
where to_date = '9999-01-01'
group by salary
order by salary desc;
使用distinct:
select distinct salary
from salaries
where to_date='9999-01-01'
order by salary desc;
网友评论