如何select第二行或第三行SQL查询
How to select the second or third row of SQL Query
我有这个查询:
SELECT TOP 6
NoMachine, COUNT(NoMachine) AS Calls
FROM
DT
GROUP BY
NoMachine
ORDER BY
Calls DESC;
这6条记录中,我要select每一条,第一条,第二条,第三条,等等
最简单的方法是什么?我正在使用 SQL Server 2008 R2。
使用row_number()
select * from
(SELECT NoMachine,
COUNT(*) AS Calls,
row_number()over(order by Calls DESC) rn
FROM DT GROUP BY NoMachine
) a where rn in (2,3)
我有这个查询:
SELECT TOP 6
NoMachine, COUNT(NoMachine) AS Calls
FROM
DT
GROUP BY
NoMachine
ORDER BY
Calls DESC;
这6条记录中,我要select每一条,第一条,第二条,第三条,等等
最简单的方法是什么?我正在使用 SQL Server 2008 R2。
使用row_number()
select * from
(SELECT NoMachine,
COUNT(*) AS Calls,
row_number()over(order by Calls DESC) rn
FROM DT GROUP BY NoMachine
) a where rn in (2,3)