分区函数Partition by使用

1、PARTITION BY使用

基本语法 over(partition by col1 order by col2);

select t.*,row_number() over( order by data_date desc) rowIndex from table t;

2、over partition by与group by的区别:

group by是对检索结果的保留行进行单纯分组,一般和聚合函数一起使用例如max、min、sum、avg、count等一块用。

partition by 对于每个每个分组返回多行,虽然也具有分组功能,但同时也具有其他的高级功能。

posted @ 2022-11-30 14:00  对白'  阅读(366)  评论(1编辑  收藏  举报