检查一个hive表列值是否包含其他列值

时间:2014-10-16 16:38:25

标签: sql hive

我有表A和表B.表一列id值类似于abc-0924-0-3,表B列id值类似于abc-0924,我想查看表A列id值是否包含表B列每行的id值。

THX

1 个答案:

答案 0 :(得分:0)

如果格式一致(即表A中ID的前8个字符等于表B中的ID),则可以使用前8个字符加入:

select
   table_a.id as table_a_id,
   case when table_b.id is null then 'Missing' else 'Not missing' end as status
from table_a
left outer join table_b
on substr(table_a.id, 1, 8) = table_b.id