count over partition by 可以去重
时间: 2024-04-25 08:21:18 浏览: 259
是的,count over partition by 可以去重。在SQL中,使用count函数结合over和partition by子句可以实现对分组后的数据进行去重计数。具体实现方式是将count(distinct ) over(partition by order by)替换成size(collect_set() over(partition by order by))。这样可以求得分组后的去重个数。这种方法适用于既要保证原数据明细表不变,又要保证分组统计数据的场景。另外,还可以使用distinct关键字结合count函数来实现去重计数,例如select distinct name,count(*) over () from t_window where substring(orderdate,1,7) = '2015-04'。还可以使用group by子句来实现去重计数,例如select name,count(*) over () from t_window where substring(orderdate,1,7) = '2015-04' group by name。
#### 引用[.reference_title]
- *1* [【hive&spark】HiveSql&SparkSql—COUNT(DISTINCT ) OVER (PARTITION BY )报错解决方案](https://blog.csdn.net/qyj19920704/article/details/126372968)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [Hive窗口函数Over partition by](https://blog.csdn.net/weixin_32265569/article/details/115475759)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文