over(partition by

pos_date是2022-07-01格式

substr装换为20220701可以进行数字排序时间

over(partition by replace(substr(pos_date,1,10),'-','') order by replace(substr(pos_date,1,10),'-','') asc)

partition by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition by用于给结果集分组,如果没有指定那么它把整个结果集作为一个分组,分区函数一般与排名函数一起使用。

row_number() over(partition by replace(substr(pos_date,1,10),'-','') order by replace(substr(pos_date,1,10),'-','') asc) as cn

加上row_number()就可以整个结果集作为一个分组进行编号

over(partition by 分组列 order by 排序列 asc) 这句话跟在select后面,作为一个结果列

posted @ 2022-07-07 11:48  Arborblog  阅读(45)  评论(0编辑  收藏  举报