基於hive-1.2.1版本select
1.join 與 where的順序join
t_user job版本
userId userName userId jobId
1 user1 4 3
2 user2 5 3
select * from t_user t1 left join job t2 on t1.userId=t2.userId where t2.jobId=3 (沒有結果)
select * from t_user t1 left join (select * from job where jobId=3 ) t2 on t1.userId=t2.userId (兩條)
2.sum()時注意null值
hive> select * from tbl3;
OK
1 1
2 2
NULL 3
3 4
hive> select sum(num1),sum(num2+num1) from tbl3;
OK
6 13
hive> select sum(num1),sum(num2+nvl(num1,0)) from tbl3;
OK 6 16