問(wèn)題描述
我有一張包含序列號(hào)文檔的表格 - 列:
I have a table full of documents with serial numbers - columns:
- docid int
- 書(shū)寫(xiě)文字
- 提交日期日期時(shí)間
...我想找出特定序列號(hào)在對(duì)表的查詢(xún)中的位置.
...and I'd like to find out where a particular serial number lies in a query against the table.
例如,如果我按 submitDate asc 對(duì)結(jié)果集進(jìn)行排序,我可能想知道文檔 34 在該排序中的位置(即它是否在位置 11?)
For example, if I ordered the resultset by submissionDate asc, I might want to know where document 34 is within that ordering (i.e. is it in position 11?)
我該怎么做?
推薦答案
看起來(lái)您正在嘗試獲取行號(hào),即使它不是要返回的行之一.您可以為此使用 CTE:
It looks like you're trying to get the row number even if that's not one of the rows being returned. You can use a CTE for that:
這當(dāng)然也需要 SQL Server 2005 或更高版本.
This also requires SQL Server 2005 or greater of course.
這篇關(guān)于獲取結(jié)果集sql server中記錄的行號(hào)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!