数据库示例
Id Name
-----------------
0 name0
1 name1
2 name2
17 name17
24 name 24
我想要一个像这样的SQL语句
SELECT waytoFindRowNumber
FROM example
WHERE Id = 17
所以我得到了结果
3 ==> the row no. of the matching record
我怎样才能得到这个结果?
由于
编辑
Id Name
-------------------------
0 name0 ==> row0
1 name1 ==> row1
2 name2 ==> row2
17 name17 ==> row3
24 name 24 ==> row4
答案 0 :(得分:1)
如何使用ROW_NUMBER内置函数;
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY Id,
ORDER BY Id) rown
FROM example
WHERE Id=17) tmp
WHERE tmp.rown = 3