在Hive中,我需要一个查询来比较One Master表和三个不同的查找表。 如果记录与所有3个查找表匹配,则记录应更新为"通过" 如果记录中的任何一个记录因任何表格不匹配而失败,则应更新记录并标记不匹配值应显示
主表:
EMPNO EMPNAME CLASS学校位置M1 M2 M3 101 SCOTT 4 MVM IDAHO 50 60 80 102 TIGER 7 MIV TEXAS 50 70 80 103 RAYON 3 MOV LONDON 80 75 80
EMPLOYEE:
EMPNO EMPNAME
101 SCOTT
102 TIGER
103 SPANGLER
104 MIKE
105 ALIGARGH
地址:
Class School Location PhoneNumber
4 MVM IDAHO 120232
6 TEM TEXAS 120394
3 MOV EDINBURGH 120479
6 PRAM VATICAN 12098
7 LEXI SALEM 12092
7 COLORS SALEM 12092
9 RAY SHIMLA 13490
商标:
M1 M2 M3
50 60 80
50 60 80
80 75 80
90 90 90
30 50 45
预期结果:
empno | empname | class | school | marks1 | marks2 | marks3 | employee | address | marks |
+--------+----------+--------+---------+---------+---------+---------+-----------+----------+--------+
| 101 | SCOTT | 3 | MOV | 50 | 70 | 80 | 1 | 1 | 1 | Matched with all 3 Records
| 102 | TIGER | 6 | MVM | 60 | 70 | 80 | 1 | 0 | 0 |Failed with Address and Marks Table, Expected Value LEXI and TEXAS in Address Table and 60 for M2 in Marks Table
| 103 | RAYON | 7 | COLORS | 90 | 90 | 90 | 0 | 0 | 1 | Failed with Employee and Address Table, Expected Value RAYON in Employee Table and LONDON in Address Table
到目前为止已经做了什么,
根据下面的查询,我可以为主表中的每条记录带来错误匹配的打印输出0和匹配的1匹配:
选择t。* ,当e.EMPNO为空且e.EMPNAME为空时的情况为0,否则1结束为EMPLOYEE ,当a.Class为null且e.school为null然后为0时,其他1以Address结尾 ,m.Marks1为null且m.Marks2为null且m.Marks3为null然后为0,否则为1,标记为
来自Master t 离开加入EMPLOYEE e 在e.EMPNO = t.EMPNO 和e.EMPNAME = t.EMPNAME 左连接地址a 在a.Class = t.Class 和a.School = t.School 左连接Marks m 在m.M1 = t.Marks1 和m.M2 = t.Marks2 和m.M3 = t.Marks3
empno | empname |班级|学校| marks1 | marks2 | marks3 |员工|地址|标记| + -------- + ---------- + -------- + --------- + --------- + --------- --------- + + + ----------- ---------- + ------- - + | 101 |斯科特| 3 | MOV | 50 | 70 | 80 | 1 | 1 | 1 | | 102 |老虎| 6 | MVM | 60 | 70 | 80 | 1 | 0 | 0 | | 103 |人造丝| 7 |颜色| 90 | 90 | 90 | 0 | 0 | 1 | + -------- + ---------- + -------- + --------- + --------- + --------- --------- + + + ----------- ---------- + ------- - +