比较两个具有相同列但数据值不同的配置单元表

时间:2019-01-09 00:10:24

标签: hive

一个数据库有两个表table1和table2。两个表的结构相同,

表1

名称得分1得分2得分最终

a 0 1 0

table2

名称得分1得分2得分最终

a 0 0 0

我想比较2个表并检查table2.score =(table1.score + 2)的值 我希望Hive查询进行检查

enter code here

select count(*)
from test.table2 a,
test.table1 b
where a.score1='2' and a.score2='0' 
and b.score1='2' and b.score2='0' 
and a.scorefinal=(b.scorefinal+2);

如果可能的话,我想以更好的方式使用连接进行比较

1 个答案:

答案 0 :(得分:0)

中选择*

(选择*, 当a.score1 = b.score1或a.score2 = b.score2或a.scorefinal =(b.scorefinal + 2)时的情况      然后1    否则0 以值结尾-此处给出一个OR条件,这意味着如果任一条件为true,则为1,如果在所有情况下都需要条件为true,则必须保持AND

来自 test.table2 a, test.table1 b

)q 值= 1

相关问题