比如想从A表中剔除B表里某字段为1的数据
create table if not exists testA(
user_id string,
user_name,
level string
);
create table if not exists testB(
user_id string,
tag int
);
--testA和testB两张表可以通过user_id相关联,现在希望两表关联,testB中tag字段为1的,从testA表里剔除出去
testA和testB两张表可以通过user_id相关联,现在希望两表关联,testB中tag字段为1的,从testA表里剔除出去
DELETE FROM testa WHERE user_id IN (SELECT user_id FROM testb WHERE tag=1);
如果只是查询,not in 或not exists 都行
select * from testA as a where not exists (select 1 from testB as b where a.user_id=b.user_id and b.tag=1);
如果是要删除A表中的数据,用in 或者exists 都行
delete testA as a where exists (select 1 from testB as b where a.user_id=b.user_id and b.tag=1);
借用楼上的sql语句试试看这个
INSERT OVERWRITE TABLE testA select * from testA as a where not exists (select 1 from testB as b where a.user_id=b.user_id and b.tag=1);