如何使用row_number()指定条件?

时间:2012-03-22 15:48:17

标签: tsql

我有以下查询:

select top 100 eid, cid, id, position, ROW_NUMBER() over(order by eid, cid, id) as record  
from standings
where record = 2

这会产生无效的列错误。

如何只检索特定的记录号。我需要这样做,一次一个地迭代结果,以便使用没有身份主键(或一般主键)的表进行数据转换

1 个答案:

答案 0 :(得分:4)

你可以从CTE拉出来

;with T as (
   select top 100 eid, cid, id, position, ROW_NUMBER() over(order by eid, cid, id) as record  
   from standings
)
select * from T where record = 2