我有代码 -
SELECT
class, revenue
FROM tblproduct
使用以下数据 -
class revenue
1 7 136.9900
2 7 24.0984
3 1318 61.9900
4 1318 39.9800
5 7 32.9800
6 1318 107.6674
有没有办法只选择类列中每个唯一行的某个计数?因此,例如,只选择两个计数将具有以下输出 -
class revenue
1 7 136.9900
2 7 24.0984
3 1318 61.9900
4 1318 39.9800
任何提示都将不胜感激!
答案 0 :(得分:1)
使用ANSI标准row_number()
功能:
select t.*
from (select t.*, row_number() over (partition by class order by id) as seqnum
from t
) t
where seqnum <= 2;