我的查询如下。
WITH CTE AS
(
SELECT EmpID, EmpName, EmpSalary,
RN = ROW_NUMBER() OVER (ORDER BY EmpSalary DESC)
FROM dbo.Salary
)
SELECT EmpID, EmpName, EmpSalary
FROM CTE
WHERE RN = @8thRow
我收到错误消息
错误报告- SQL错误:ORA-00923:找不到所需的FROM关键字 00923. 00000-“未在预期的位置找到FROM关键字”。
有人可以解释代码有什么问题吗?
答案 0 :(得分:0)
语法错误;一个基于Scott模式的示例:
SQL> select ename, sal from emp order by sal;
ENAME SAL
---------- ----------
SMITH 920
JAMES 950
ADAMS 1100
WARD 1250
MARTIN 1250
MILLER 1300
TURNER 1500 -- 8th --> you need this one
ALLEN 1600
CLARK 2450
BLAKE 2850
JONES 2975 -- ...
SCOTT 3000 -- 3rd
FORD 3000 -- 2nd
KING 10000 -- 1st, when sort is DESCending
14 rows selected.
SQL> with cte as
2 (select empno, ename, sal,
3 row_number() over (order by sal desc) rn
4 from emp
5 )
6 select empno, ename, sal
7 from cte
8 where rn = 8;
EMPNO ENAME SAL
---------- ---------- ----------
7844 TURNER 1500
SQL>