当前位置:   article > 正文

一条sql搞定设备在线离线统计问题

一条sql搞定设备在线离线统计问题

业务场景

对不同状态的设备进行统计

SELECT count(1)                                          AS total,
               sum(CASE WHEN handle_state = 1 THEN 1 ELSE 0 END) AS handleNum,
               sum(CASE WHEN handle_state = 2 THEN 1 ELSE 0 END) AS noticeNum,
               sum(CASE WHEN handle_state = 3 THEN 1 ELSE 0 END) AS developNum,
               sum(CASE WHEN handle_state = 4 THEN 1 ELSE 0 END) AS archiveNum
        FROM fire_handle
        WHERE to_days(alarm_time) = to_days(
                now())
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/424217
推荐阅读
相关标签
  

闽ICP备14008679号