日期:2014-05-17 浏览次数:21278 次
--这不就是1,6,3了嘛
select sum(A) A,sum(B) B,sum(C) C from 你的表;
declare @T table (A int,B int,C int)
insert into @T
select 0,0,1 union all
select 0,2,1 union all
select 1,2,1 union all
select 0,0,0 union all
select 0,2,0 union all
select 0,0,0
--如果数据中有1,-1,0,这样的判断就不对了。
select * from @T where A+B+C<>0
/*
A B C
----------- ----------- -----------
0 0 1
0 2 1
1 2 1
0 2 0
*/
--第一种方式
select * from @T where
(case when A=0 then 1 else 0 end +
case when B=0 then 1 else 0 end +
case when C=0 then 1 else 0 end )<>3
--第二种方式
select * from @T
except
select * from @T where A=0 and B=0 and C=0
--第三种方式
select * from @T t
where not exists
(select top 1 * from @T where t.A=0 and t.B=0 and t.C=0)