0

我想在 SQL Server 表中选择记录集。

在 SQL Server 中,我可以这样做:

select TOP 40,60 * 
from sometable
order by name

我想得到第 40 到第 60 行。

谢谢你。

4

4 回答 4

0

LIMIT 在 Oracle 中存在,但参数不同,第一个参数指定要返回的第一行的偏移量,第二个指定要返回的最大行数。初始行的偏移量为 0(不是 1):

SELECT * FROM sometbl Order by name LIMIT 40,100;  # Retrieve rows 41-100

或者你可以继续;

SELECT * FROM
(
   SELECT st.*, Row_Number() OVER (ORDER BY name) rn FROM sometable st
) 
WHERE rn BETWEEN 40 AND 60;
于 2013-11-07T05:38:30.407 回答
0

使用Row_number函数并获取您需要的行

WITH tmp AS  
    (SELECT *, ROW_NUMBER() OVER (ORDER BY a.name) AS 'rn', a.* FROM table a)
    SELECT * FROM tmp WHERE rn BETWEEN 40 AND 60
于 2013-11-07T05:41:04.547 回答
0

试试这个

SELECT * FROM
(
  SELECT table.*, Row_Number() OVER (ORDER BY name) rank FROM table 
) 
WHERE rank BETWEEN 40 AND 60;
于 2013-11-07T06:18:29.817 回答
0

我做了这个查询

WITH temp AS
( SELECT *,    ROW_NUMBER() OVER (ORDER BY name) AS 'RowNumber'
   FROM sometable 
) 
SELECT * FROM temp WHERE RowNumber BETWEEN 40 AND 60

谢谢大家的评论。

于 2013-11-07T06:40:21.813 回答