求解。。。求解。。。求解

屌丝小白 2013-09-24 05:27:30
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 里面做判断么?
...全文
169 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cloud_Hero 2013-09-27
  • 打赏
  • 举报
回复
当 F1和F2、F3同时等于0,表示啥都没查到,所以就查不出这条记录了。
xxfvba 2013-09-25
  • 打赏
  • 举报
回复
引用 4 楼 ap0405140 的回复:
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)
not的用法
唐诗三百首 2013-09-24
  • 打赏
  • 举报
回复
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)
發糞塗牆 2013-09-24
  • 打赏
  • 举报
回复
啃爹的现在才能回复
Andy__Huang 2013-09-24
  • 打赏
  • 举报
回复
--换个角度,只要它是其中之一就查出来

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
where cAlarmtype='火警' or cAlarmtype='故障' or cAlarmtype='管理信息'
發糞塗牆 2013-09-24
  • 打赏
  • 举报
回复
要么在case when那里判断,要么在where那里判断

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧