题目描述
找出所有员工当前(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`));
输入描述:
无
输出描述:
salary946929440988958880707405772527597554331125828
--方法1:distinct+order by
select distinct salary
from salaries
where to_date='9999-01-01'
order by salary desc;
--方法2:distinct+order by
select salary
from salaries
where to_date='9999-01-01'
group by salary
order by salary desc;
--补充:WHERE语句在GROUP BY语句之前,SQL会在分组之前计算WHERE语句。HAVING语句在GROUP BY语句之后,SQL会在分组之后计算HAVING语句。
说明: 对于distinct与group by的使用: 1.当对系统的性能高并且数据量大时使用group by 2.当对系统的性能不高时或者使用数据量少时两者皆可 3.尽量使用group by