我选择了:
select col1,col2,col3.....sum(colx) from t1 group by col1,col2,col3...
如何:
1-显示排序最高的前100行(colx1)ASC
2-添加行号
答案 0 :(得分:2)
使用TOP()
和ROW_NUMBER()
:
SELECT TOP 100 t.*,
ROW_NUMBER() OVER(ORDER BY sum_col DESC) as row_number
FROM(
select col1,col2,col3.....
sum(colx) as sum_col
from t1
group by col1,col2,col3...) t
ORDER BY sum_col
答案 1 :(得分:1)
使用ROW_NUMBER
和TOP
:
SELECT TOP(100)
col1,
col2,
col3,
SUM(colx),
Rn = ROW_NUMBER() OVER(ORDER BY SUM(colx) DESC)
FROM t1
GROUP BY
col1,
col2,
col3
ORDER BY Rn