select * from employee e
where 2 = (select count(distinct(e1.sal))
from employee e1
where e.sal > e1.sal);
例如,给定以下员工数据:
Employee Salary Count Greater than
(Distinct) these Salaries
Joe $80,000 0 Lowest Salary
Kate $80,000 0 Lowest Salary
Lee $85,000 1 $80,000
Chris $85,000 1 $80,000
Matt $85,000 1 $80,000
Mike $90,000 2 $85,000,$80,000
June $90,000 2 $85,000,$80,000
Jack $100,000 3 $90,000,$85,000,$80,000
The query returns
Mike $90,000
June $90,000
because 90,000 is greater than 80,000 and 85,000
Notice that Jack is not returned because his salary is greater than 3 other salaries. Also note there are 5 employees with a salary less than Mike's and June's but the distinct keyword forces the count to 2.
2条答案
按热度按时间wz8daaqr1#
查询返回Salary高于2其他薪资的所有员工。括号是误导性的,不需要。
例如,给定以下员工数据:
nbewdwxp2#
如前所述,数字2周围的括号是无用的。等效查询可以是
小提琴
正如您在示例中看到的,您正在搜索雇员,其中雇员表中存在两个不同的较低工资。