用于按deptno查找员工组第n个最大sal的SQL查询
我遇到错误**缺少表达式**Group By位于where子句之后:用于按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; 分组方式应
我不完全确定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;