Possible Duplicate:
How to select the nth row in a SQL database table?可能重复:如何选择SQL数据库表中的第n行?
I have a table that I want to select Select 1 record and in other command I want to select second row and in other command 3th row and ... how can I select for example 4th record from top of table without having the row number . just I want to select 4th row from top of table . how can I do this ?
我有一个表,我想选择选择1记录,在其他命令中我想选择第二行,在其他命令第3行和...如何选择例如从表顶部的第4条记录而没有行号。只是我想从表格顶部选择第4行。我怎样才能做到这一点 ?
2 个解决方案
#1
3
you can select the 4th row by this code in MS sql server.
您可以在MS sql server中通过此代码选择第4行。
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY DayRangeId ASC) AS rownumber,
DayRangeId
FROM DayRangeTable
) as temptablename
WHERE rownumber = 4
#2
0
You want the first row, then the second row, then the third row and then the fourth row?
你想要第一行,然后是第二行,然后是第三行,然后是第四行?
Can't you select the top n
rows, and itterate through them?
你不能选择前n行,并通过它们进行迭代?
I'm not sure what you mean by without having the row number
though. Do you mean "Select the 4th row without knowing I need the 4th row"???
如果没有行号,我不确定你的意思。你的意思是“选择第四行而不知道我需要第四行”???
If you really need a piece of SQL that can select a specific row...
如果你真的需要一块可以选择特定行的SQL ...
;WITH
sequenced_data AS (
SELECT ROW_NUMBER() OVER (ORDER BY <whatever fields>) AS row_id, * FROM myTable
)
SELECT
TOP 1 *
FROM
sequenced_data
WHERE
row_id = @n
#1
3
you can select the 4th row by this code in MS sql server.
您可以在MS sql server中通过此代码选择第4行。
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY DayRangeId ASC) AS rownumber,
DayRangeId
FROM DayRangeTable
) as temptablename
WHERE rownumber = 4
#2
0
You want the first row, then the second row, then the third row and then the fourth row?
你想要第一行,然后是第二行,然后是第三行,然后是第四行?
Can't you select the top n
rows, and itterate through them?
你不能选择前n行,并通过它们进行迭代?
I'm not sure what you mean by without having the row number
though. Do you mean "Select the 4th row without knowing I need the 4th row"???
如果没有行号,我不确定你的意思。你的意思是“选择第四行而不知道我需要第四行”???
If you really need a piece of SQL that can select a specific row...
如果你真的需要一块可以选择特定行的SQL ...
;WITH
sequenced_data AS (
SELECT ROW_NUMBER() OVER (ORDER BY <whatever fields>) AS row_id, * FROM myTable
)
SELECT
TOP 1 *
FROM
sequenced_data
WHERE
row_id = @n