开发者

cannt get a record by the row number

开发者 https://www.devze.com 2023-01-05 11:07 出处:网络
i get an error with this query select ID, ROW_NUMBER() OVER(ORDER BY ID) as num from T_TASK where ROW_NUMBER() = 5

i get an error with this query

select ID, ROW_NUMBER() OVER(ORDER BY ID) as num from T_TASK where ROW_NUMBER() = 5

and this one

select ID, ROW_NUMBER() OVER(ORDER BY ID) as num from T_TASK where num = 4

whats w开发者_开发问答rong with the queries?


SELECT ID
FROM
(select ID, ROW_NUMBER() OVER(ORDER BY ID) as rownum from T_TASK) dr
WHERE rownum = 5


Use a subquery:

SELECT ID
FROM (
    SELECT ID, ROW_NUMBER() OVER(ORDER BY ID) AS num
    FROM T_TASK
) T1 WHERE num = 5


1 You can't use windows functions directly on the WHERE clause

2 The same is applied to alias name too

0

精彩评论

暂无评论...
验证码 换一张
取 消