当前位置: 代码迷 >> Sql Server >> 求SQL一话语
  详细解决方案

求SQL一话语

热度:61   发布时间:2016-04-27 10:43:23.0
求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 )=3and (a+b+c+d+e+f)>=6
  相关解决方案