select a.* from entry_data_fxj_cl a left join exit_data b
on trim(a.ecardid) = trim(b.ecardid) and abs(a.entrytime-b.entrytime)>60000
where trim(b.ecardid) IS NULL
解决方法是将非相等联接条件移动到 WHERE 并添加 OR IS NULL 允许左连接。请参见sql代码中的注解:
select *
from
(--move non-equality condition to the where + OR is null to allow left join
select a.*, b.ecardid as b_ecardid
from entry_data_fxj_cl a left join exit_data b
on trim(a.ecardid) = trim(b.ecardid)
where abs(a.entrytime-b.entrytime)>60000 or b.ecardid is NULL --allow left join
)s
where b_ecardid IS NULL --filter only rows for which b.ecardid is not found
select edf.*
from entry_data_fxj_cl edf
where not exists (select 1
from exit_data ed
where trim(ed.ecardid) = trim(edf.ecardid) and
ed.entrytime > edf.entrytime - 60000 and
ed.entrytime < edf.entrytime + 60000
);
2条答案
按热度按时间pqwbnv8z1#
解决方法是将非相等联接条件移动到
WHERE
并添加OR IS NULL
允许左连接。请参见sql代码中的注解:yv5phkfx2#
我倾向于这样写:
你在 hive 里用吗?