SQL練習:SQL8_簡單
題目: 找出所有員工目前(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`));

題解
#方式1:DISTINCT
SELECT DISTINCT salary
FROM salaries
WHERE to_date = '9999-01-01'
ORDER BY salary DESC
#方式2:GROUP BY
SELECT salary
FROM salaries
WHERE to_date = '9999-01-01'
GROUP BY salary
ORDER BY salary DESC
關于DISTINCT與GROUP BY性能的問題:MySQL官網
個人整理的筆記,僅供學習使用,有問題麻煩指正。
題目及解答思路均來源于:牛客網