Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于按deptno查找员工组第n个最大sal的SQL查询_Sql - Fatal编程技术网

用于按deptno查找员工组第n个最大sal的SQL查询

用于按deptno查找员工组第n个最大sal的SQL查询,sql,Sql,我遇到错误**缺少表达式**Group By位于where子句之后: 我不完全确定sub-select是否真的做了您希望它做的事情,但我现在无法测试它。我认为您的语法无效。 正确的sql GROUP BY语法为 select deptno, distinct(sal) from emp e1 where 3 = (select count(distinct(sal)) from emp e2 where e1.sal<=e2.sal) group by deptno,sal; 分组方式应

我遇到错误**缺少表达式**

Group By位于where子句之后:


我不完全确定sub-select是否真的做了您希望它做的事情,但我现在无法测试它。

我认为您的语法无效。 正确的sql GROUP BY语法为

select deptno, distinct(sal)
from emp e1
where 3 = (select count(distinct(sal)) from emp e2 where e1.sal<=e2.sal)
group by deptno,sal;
分组方式应该是最后一个。
更多信息:

您的查询似乎有误。请发布输入表和预期输出。
select deptno, distinct(sal)
from emp e1
where 3 = (select count(distinct(sal)) from emp e2 where e1.sal<=e2.sal)
group by deptno,sal;
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;