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

求解。求解。求解解决方法

2013-09-28 
求解。。。求解。。。求解selectisnull(sum(case when cAlarmtype火警 then 1 else 0 end),0) asF1,isnull(su

求解。。。求解。。。求解
select
isnull(sum(case when cAlarmtype='火警' then 1 else 0 end),0) as  F1,
isnull(sum(case when cAlarmtype='故障' then 1 else 0 end),0) as  F2,
isnull(sum(case when cAlarmtype='管理信息' then 1 else 0 end),0) as  F3
from tab
有需求,当 F1和F2、F3同时等于0的时候就查不出这条数据。
当然我知道这写法不对,但就这意思:where (F1 !=0 AND F2 !=0 AND F3 !=0)
求大神解答,因为我用了分页的存储过程,能在where 里面做判断么?
[解决办法]
try this,


select F1,F2,F3 from
(select
 isnull(sum(case when cAlarmtype='火警' then 1 else 0 end),0) as  F1,
 isnull(sum(case when cAlarmtype='故障' then 1 else 0 end),0) as  F2,
 isnull(sum(case when cAlarmtype='管理信息' then 1 else 0 end),0) as  F3
 from tab) t
where not (F1=0 and F2=0 and F3=0)

热点排行