我正在使用SQL在SQL Server 2008中生成序列号
SELECT ROW_NUMBER() OVER ( ORDER BY Column ) AS SrNo
以上SQL将按升序生成SrNo
1 2 3 4 5
但我想按降序生成它。
5 4 3 2 1
答案 0 :(得分:2)
您需要对ORDER BY列DESC进行排序
SELECT SrNo FROM
(SELECT ROW_NUMBER() OVER (ORDER BY YOUR_COLUMN ) AS SrNo FROM YOUR_TABLE) X
ORDER BY SrNo DESC
答案 1 :(得分:1)
select * FROM (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) AS SNO, ColumnName FROM table
)r
ORDER BY SNO Desc