我需要将此sql转换为hive ql。我发现hive
没有运营商in
。
select type,sum(cost) as Cost from TableName
WHERE trans_id in (SELECT trans_id FROM TableName WHERE type=0)
group by type;
答案 0 :(得分:1)
将其写为LEFT SEMI JOIN:
select type,sum(cost) as Cost from T1
LEFT SEMI JOIN T2 ON T1.trans_id = T2.trans_id
WHERE type=0
group by type;
与Hive 0.13一样,您不必以Hive 0.13 supports IN/EXISTS clause with subqueries(HIVE-784)执行此操作。