首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求SQL一话语

2012-10-18 
求SQL一语句表Table有6个都为INT行字段(a、b、c、d、e、f),用什么语句能检索出随便3个的组合大于0,其他3个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 

热点排行