日期:2014-05-16  浏览次数:20443 次

求解。。。求解。。。求解
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)