hive 中使用grouping SETS时遇见对坑
:hive报错
Grouping sets aggregations (with rollups or cubes) are not allowed if aggregation function parameters overlap with the aggregation functions columns
select p.city_name,p.rent_type,p.sf_type,p.sign_type
,sum(case when rent_type= '合租' then 1 else 2 end ) as rooms
from rooms
group by p.city_name,p.rent_type,p.sf_type,p.sign_type
grouping SETS(
p.city_name,
(p.city_name,p.rent_type),
(p.city_name,p.sf_type),
(p.city_name,p.sign_type),
(p.city_name,p.rent_type,p.sf_type),
(p.city_name,p.rent_type,p.sign_type),
(p.city_name,p.sf_type,p.sign_type),
(p.city_name,p.rent_type,p.sf_type,p.sign_type)
))b
在调试过程中 有些 平台是支持对比如 pyspark
sum(case when rent_type= '合租' then 1 else 2 end ) as rooms
rent_type 为分组字段
但在hive服务器有时候不支持