例如,表中有五条记录我想找到第三条如何为任何元素计数创建函数
答案 0 :(得分:1)
您可以使用ROW_NUMBER
:
WITH CTE AS( SELECT RN = ROW_NUMBER() OVER (ORDER BY Column ASC), t.* FROM dbo.Table t )
SELECT * FROM CTE
WHERE RN = (SELECT COUNT(*) FROM dbo.Table) / 2 + 1
答案 1 :(得分:0)
你可以试试这个:
SELECT TOP 3 * FROM tab EXCEPT SELECT TOP 2 * FROM tab
答案 2 :(得分:0)
另一个没有生成和额外字段的选项是使用 WITH TIES 子句
Select Top 1 with ties *
From YourTable
Order By case when row_number() over (Order By SomeValue) = (Select count(*) From YourTable) / 2 + 1 then 1 else 2 end