开发者

cannt get a record by the row number

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜