日期:2014-05-20 浏览次数:20834 次
select name,status1,status2,status3 from A where status1=0 and status2=0 and status3=0
------解决方案--------------------
SELECT * FROM 表 A WHERE status1=0 AND status2=0 AND status3 =0
and NOTEXIISTS(SELECT NAME FROM 表 WHERE status1<>0 OR status2<>0 OR status3 <>0 WHERE NAME=A.NAME)
------解决方案--------------------
with tb1 as( select 'aa' name,0 status1,0 status2,1 status3 from dual union all select 'aa' name,0 status1,0 status2,0 status3 from dual union all select 'bb' name,1 status1,0 status2,1 status3 from dual union all select 'bb' name,0 status1,0 status2,0 status3 from dual union all select 'cc' name,0 status1,0 status2,0 status3 from dual union all select 'cc' name,0 status1,0 status2,0 status3 from dual ) select tt.name,tt.status1,tt.status2,tt.status3 from( select name, (select sum(status1) from tb1 where name=t.name) status1, (select sum(status2) from tb1 where name=t.name) status2, (select sum(status3) from tb1 where name=t.name) status3 from tb1 t group by name) tt where status1=0 and status2=0 and status3=0; --result NAME STATUS1 STATUS2 STATUS3 ---- ---------- ---------- ---------- cc 0 0 0
------解决方案--------------------
select * from 表A where a.name not in (select name from 表 where status1<>0 or status2<>0 or status3<>0)
------解决方案--------------------
select * from test where TEST.NAME not in (select t.name from TEST t where status1!=0 or status2!=0 or status3!=0 );
------解决方案--------------------
select a.name, a.status1, a.status2, a.status3 from a where a.name not in(select a.name from a where a.status1='1' or a.status2='1' or a.status3='1')