例子:某主机下有5149个设备,设备分不同类别,设备运行会有不同状态(1-正常、2-告警、3-故障、0-离线)

sql:

SELECT t.DEVICE_TYPE_NAME,
SUM(CASE t.DEVICE_STATUS WHEN \’1\’ THEN 1 ELSE 0 END) AS \’正常\’,
SUM(CASE t.DEVICE_STATUS WHEN \’3\’ THEN 1 ELSE 0 END) AS \’故障\’,
SUM(CASE t.DEVICE_STATUS WHEN \’0\’ THEN 1 ELSE 0 END) AS \’离线\’,
SUM(CASE t.DEVICE_STATUS WHEN \’2\’ THEN 1 ELSE 0 END) AS \’告警\’
FROM(SELECT * FROM `device_info` WHERE FIRE_SYSTEM_ID=1 and CATEGORY_ID=2 and DELETED=0 AND DIST_ID=5) t
GROUP BY t.DEVICE_TYPE_NAME

查询结果:

 

页面效果:

 

版权声明:本文为zwqh原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zwqh/p/9565620.html