将SQL运算符转换为Hive QL

时间:2014-03-18 07:35:32

标签: hive hiveql

我需要将此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;

1 个答案:

答案 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 subqueriesHIVE-784)执行此操作。