柠檬也有梦
2020-06-19 10:58
采纳率: 50%
浏览 533

sqlserver 如何使用count在一条数据中查询呢

两个查询sql如何合并在一起呢

select
'区域' as Area,
'名称' as MineName,
count(1) as '在线'
from sys_PointInfo 
where sysCode=121  and Value =0
group by Area,MineName

select
'区域' as Area,
'名称' as MineName,
count(1) as '不在线'
from sys_PointInfo 
where sysCode=121  and (Value !=0 or value is null)
group by Area,MineName 

图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • FEN_TA 2020-06-19 13:59
    已采纳

    select
    '区域' as Area,
    '名称' as MineName,
    count(case when Value =0 then 1 end) as '在线',
    count(case when (Value !=0 or value is null) then 1 end) as '不在线'
    from sys_PointInfo
    where sysCode=121
    group by Area,MineName

    点赞 2 打赏 评论
  • cwkisasb 2020-06-19 11:18

    把这两个子查询连接查询,不会的话,把你的表结构和数据sql发出来看看,还有,你这个查询语句在查什么东西,完全没看懂

    点赞 打赏 评论

相关推荐 更多相似问题