database - In hive, Need a values from a table to compared with 3 different tables -
need compare 1 table different tables:
in hive, need 1 query compare 1 table 3 different lookup tables.
if record matched 3 lookup tables, record should updated "passed"
if 1 of record failed mis-match of tables, record should updated , marked "failed reason" , correct value should displayed
say:
master table
empno empname class school marks1 marks2 marks3 101 scott 3 mov 50 70 80 102 tiger 6 mvm 60 70 80 103 rayon 7 colors 90 90 90
lookup tables:
employee:
empno empname 101 scott 102 tiger 103 spangler 104 mike 105 aligarh
address:
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
marks:
m1 m2 m3 50 60 80 50 70 80 80 74 79 90 90 90 30 50 45
here, first record master table compared employee table, address table & markts table
1-> empno 101 , empname scott master table matches first record in employee lookup table, matches third record in address lookup table & second record in marks lookup table - should updated passed in tables
2-> empno 102 , empname tiger matches second record in employee lookup table not match record in address lookup table , not match marks table should updated not match address , marks table
3-> empno 103 , empname rayon not match record in employee lookup table matches sixth record in address lookup table , matches fourth record in marks lookup table
record 1 in master table should updated passed in 3 tables record 2 in master table should updated failed in address , marks lookup table record 3 in master table should updated failed in employee lookup table
+-------+---------+-------+---------+--------+--------+--------+----------------------------------------------------------------------+----------------------------------------------------+ | empno | empname | class | school | marks1 | marks2 | marks3 | result | reason | +-------+---------+-------+---------+--------+--------+--------+----------------------------------------------------------------------+----------------------------------------------------+ | 101 | scott | 3 | mov | 50 | 70 | 80 | matched 3 tables | na | | 102 | tiger | 6 | mvm | 60 | 70 | 80 | did not match in address , mark table | school value should mvm & marks 1 should 60 | | 103 | rayon | 7 | colors | 90 | 90 | 90 | did not match in employee table other tables matched | empname should rayon | +-------+---------+-------+---------+--------+--------+--------+----------------------------------------------------------------------+----------------------------------------------------+
this gives basic representation, can manipulate further pleased.
select t.* ,case when e.empno null 0 else 1 end employee ,case when a.class null 0 else 1 end address ,case when m.m1 null 0 else 1 end marks master t left join employee e on e.empno = t.empno , e.empname = t.empname left join address on a.class = t.class , a.school = t.school left join marks m on m.m1 = t.marks1 , m.m2 = t.marks2 , m.m3 = t.marks3 ;
+--------+----------+--------+---------+---------+---------+---------+-----------+----------+--------+ | empno | empname | class | school | marks1 | marks2 | marks3 | employee | address | marks | +--------+----------+--------+---------+---------+---------+---------+-----------+----------+--------+ | 101 | scott | 3 | mov | 50 | 70 | 80 | 1 | 1 | 1 | | 102 | tiger | 6 | mvm | 60 | 70 | 80 | 1 | 0 | 0 | | 103 | rayon | 7 | colors | 90 | 90 | 90 | 0 | 0 | 1 | +--------+----------+--------+---------+---------+---------+---------+-----------+----------+--------+
Comments
Post a Comment