hive 在使用 count(distinct ) over 时报错,提示 FAILED: SemanticException [Error 10025]: Line 1:123 Expression not in GROUP BY key 解决办法
参考了很多帖子,都没有说明解决办法。
我给出一个折中的参考方案,在聚合前,先将数据去重,再cout() over 即可。
下面给出我的参考范例
某股东一致行动人持有相同的股票,需要求出改一致行动人累计的上榜次数及持有股票累计次数。
select dt,holder_list, count(distinct holder_list) over(partition by dt) as rn,
count(distinct code) over(partition by dt, holder_list) as rn2
from XXXX
#####################
# 提示报错 Expression Not In Group By Key
需要去重后再去统计
### 统计股东一致行动人累计上榜次数
select dt, holder_list, count(dt) over (partition by holder_list order by dt) as rn
from
(select distinct dt, holder_list
from XXXX
)
#### 统计股东一致行动人持有股票累计上榜次数
select dt, code, count(code) over (partition by holder_list, code order by dt) as rn
from
(select distinct dt, holder_list, code
from XXXX
)
可以得到最后类似 count(distinct) 效果
此贴来自汇总贴的子问题,只是为了方便查询。
总贴请看置顶帖:
pyspark及Spark报错问题汇总及某些函数用法。
https://blog.csdn.net/qq0719/article/details/86003435