日期:2014-05-17  浏览次数:20571 次

求SQL一语句
表Table有6个都为INT行字段(a、b、c、d、e、f),用什么语句能检索出随便3个的组合大于0,其他3个=0的数据
例如,a、c、e3个字段的值都大于0,而b、d、f值等于0就满足条件。

------解决方案--------------------
SQL code

select * from TableName 
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+case when d=0 then 1 else 0 end
      +case when e=0 then 1 else 0 end+case when f=0 then 1 else 0 end )=3
and (a+b+c+d+e+f)>=6