1

私はテーブルを持っています:id, Group, Status, Subject

group = 2 AND status = 2の行が必要ですが、最初の8つの結果(順序付け)をスキップしたいと思いidます。これは私が試したものですが、最初の8行をスキップしません。

SELECT TOP 3 [id], LEFT ([subject],30) AS Title 
FROM [Katavot] 
    WHERE (([Status] = @Status) AND ([Group] = @Group)) 
ORDER BY [id] DESC
4

3 に答える 3

1
;WITH Katavod_Modified AS 
(
    SELECT id, LEFT ([subject],30) As Subject, [Group], [Status],  ROW_NUMBER() OVER (ORDER BY id) RN
    FROM [Katavot]
)
SELECT TOP 3 [id], LEFT ([subject],30) AS Title FROM [Katavod_Modified] WHERE 
(([Status] = @Status) AND ([Group] = @Group) AND (RN > 8)) ORDER BY [id] DESC 

これと非常によく似ています。

于 2013-01-28T00:24:42.693 に答える
1

row_numberに基づく

WITH MyResult AS
{
SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS RowNumber, [id], LEFT ([subject],30) AS Title 
FROM [Katavot] 
    WHERE (([Status] = @Status) AND ([Group] = @Group)) 
ORDER BY [id] DESC
}
SELECT [id], Title 
FROM MyResult
WHERE RowNumber BETWEEN 9 AND 12
于 2013-01-28T00:27:45.833 に答える
-1

MySQL:

LIMIT x, y

MSSQL:

select top y *
from <table>
where <unique id> not in (select top x <unique id> from <table> order by <unique id>)
from <table> order by <unique id>
于 2013-01-28T00:28:10.170 に答える