日期:2014-05-17 浏览次数:21034 次
with t1 as( select '1' id ,'test1' name, '1' codes from dual union all select '1' id ,'test1' name, '11' codes from dual union all select '2' id ,'test2' name, '2' codes from dual union all select '2' id ,'test2' name, '22' codes from dual union all select '3' id ,'test3' name, '3' codes from dual ), t2 as( select '1' id ,'test1' name, '11' codes from dual union all select '1' id ,'test1' name, '111' codes from dual union all select '2' id ,'test2' name, '2' codes from dual )
SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE id=t1.id AND NAME=t1.NAME ) AND codes NOT IN (SELECT DISTINCT codes FROM t2) 或者 SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE id=t1.id AND NAME=t1.NAME ) MINUS SELECT * FROM t2
------解决方案--------------------
select * from t1 where not exists (select 1 from t2 where t1.id=t2.id and t1.name= t2.name and t1.codes=t2.codes) and exists(select 1 from t2 where t1.id=t2.id and t1.name= t2.name);
------解决方案--------------------
minus试试看