OVER中OVER(PARTITION BY... ORDER BY...)的使用

select PGM_ID,PGM_SH_CFM_CD,row_number() over(partition by PGM_ID order by PGM_SH_CFM_CD)rn,
count(*) over(partition by PGM_ID) cnt from MED_PGM_SH_CFM_H

查出的数据如下

最近使用到了ORACLE的分析函数随手记录一下。

over(partition by ... order by ...)这个函数,即把一组数据按照制定的字段进行分割成各种组,然后组内按照某个字段排序。其他常用的还有:
count() over(partition by ... order by ...)
max() over(partition by ... order by ...)
min() over(partition by ... order by ...)
sum() over(partition by ... order by ...)
avg() over(partition by ... order by ...)
 

猜你喜欢

转载自blog.csdn.net/dx94sg/article/details/85695918