给该表加序号:
select ord,num,row_number()over(order by ord asc) nums
from cx.over_test;
按ord进行排序;
根据ord进行分组排序:
select ord,num,row_number()over(partition by ord order by ord asc) nums
from cx.over_test;
ord相同的,按1重新排序;
那如果我们只想取这每一组的第一个怎么办?
发现报错了;
over里头的分组及排序的执行晚于“where,group by,order by”的执行。
所以:
select ord,num,nums from (select ord,num,row_number()over(partition by ord order by ord,num asc) nums
from cx.over_test) a
where nums<2;