Hive 蜂巢中的嵌套选择
我可以在蜂巢中使用不同条件嵌套Hive 蜂巢中的嵌套选择,hive,Hive,我可以在蜂巢中使用不同条件嵌套选择?e、 g 如果我有以下两个配置单元查询: select percentile(x, 0.95) from t1 where y = 1; select percentile(x, 0.95) from t1 where y = 2; 我可以在一个查询中选择上面的两个百分位数吗?类似(它不起作用): 您可以使用UNION ALL执行此操作,例如: select * from (select percentile(x, 0.95) from t1
选择?e、 g
如果我有以下两个配置单元查询:
select percentile(x, 0.95)
from t1
where y = 1;
select percentile(x, 0.95)
from t1
where y = 2;
我可以在一个查询中选择上面的两个百分位数吗?类似(它不起作用):
您可以使用UNION ALL
执行此操作,例如:
select * from
(select percentile(x, 0.95)
from t1
where y = 1
union all
select percentile(x, 0.95)
from t1
where y = 2) x;
如果表格很大,我想您应该避免对其进行多次扫描
select percentile( if( y = 1 , x, 0 ), 0.95 ) as percentile_1
percentile( if( y = 2 , x, 0 ), 0.95 ) as percentile_2
from t1;
也可以尝试:
select percentile( case when y=1 then x else null end, 0.95) as p95_1
, percentile( case when y=2 then x else null end, 0.95) as p95_2
from table;
percentile()将忽略空值 编辑以修复一个小的语法问题。
select percentile( case when y=1 then x else null end, 0.95) as p95_1
, percentile( case when y=2 then x else null end, 0.95) as p95_2
from table;