For the first question, why not just use?
(对于第一个问题,为什么不使用?)
SELECT COUNT(*) FROM myTable
to get the count.
(得到数。)
And for the second question, the primary key of the row is what should be used to identify a particular row.
(对于第二个问题,该行的主键是应该用于标识特定行的内容。)
Don't try and use the row number for that. (不要尝试使用行号。)
If you returned Row_Number() in your main query,
(如果您在主查询中返回Row_Number(),)
SELECT ROW_NUMBER() OVER (Order by Id) AS RowNumber, Field1, Field2, Field3
FROM User
Then when you want to go 5 rows back then you can take the current row number and use the following query to determine the row with currentrow -5
(然后,当您想要返回5行时,您可以获取当前行号并使用以下查询来确定具有currentrow -5的行)
SELECT us.Id
FROM (SELECT ROW_NUMBER() OVER (ORDER BY id) AS Row, Id
FROM User ) us
WHERE Row = CurrentRow - 5
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…