我有一个sql表:
C1 | C2 | C3
aa | bb | 21
gg | hh | 53
dd | yy | 37
我想要在C3中具有最高值的前5000行,但我希望我的数据按C1排序 我怎样才能做到这一点?感谢。
答案 0 :(得分:2)
使用分析ROW_NUMBER
功能:
SELECT C1, C2, C3
FROM (
SELECT C1, C2, C3, ROW_NUMBER() OVER (ORDER BY C3 DESC) AS C3Rank
FROM myTable
)
WHERE C3Rank <= 500
ORDER BY C1