任何人都可以解释以下查询获得3个最高薪水吗?
select distinct sal
from emp a
where 3 >= (select count(distinct sal)
from emp b
where a.sal <= b.sal)
order by a.sal desc;
Run Code Online (Sandbox Code Playgroud)
有人建议我使用上面的查询来获得3个最大值.表中的工资.我不明白查询的下面部分发生了什么:
3>= (select count(distinct sal)
from emp b
where a.sal <= b.sal) ;
Run Code Online (Sandbox Code Playgroud)
有人能解释一下吗?如果还有其他方法可以得到相同的结果,请咨询我
empid sal
===============
1 300
2 50
3 400
4 200
5 150
================
select distinct sal from emp a where 3 --outer query
>=
(select count(distinct sal) from emp b --inner query(correlated)
where a.sal <= b.sal) order by a.sal desc;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6668 次 |
| 最近记录: |