I need convert this sql to hive ql. I find the hive don't have operator in .

select type,sum(cost) as Cost from TableName 
WHERE trans_id in (SELECT trans_id FROM TableName WHERE type=0)
group by type;
有帮助吗?

解决方案

Write it as a 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;

As with Hive 0.13 you won't have to do this as Hive 0.13 supports IN/EXISTS clause with subqueries (HIVE-784).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top