读书人

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

发布时间: 2013-09-28 10:01:20 作者: rapoo

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

读书人网 >SQL Server

热点推荐