SELECT * FROM ( SELECT COUNT(*) AS JLGZTZ FROM DISPATCH.T_FAULT_DATA_RESULT WHERE EQUIP_TYPE = 1 ) , ( SELECT COUNT(*) AS DXGZTZ FROM DISPATCH.T_FAULT_DATA_RESULT WHERE EQUIP_TYPE = 1 AND FAULT_TYPE = 1 ) , ( SELECT COUNT(*) AS CHCG FROM DISPATCH.T_FAULT_DATA_RESULT WHERE EQUIP_TYPE = 1 AND FAULT_TYPE = 1 AND ISCH = 1 )优化这个sql,换一种简单的方法写出来
时间: 2024-02-10 10:07:07 浏览: 128
可以使用子查询来优化这个 SQL:
```
SELECT
(SELECT COUNT(*) FROM DISPATCH.T_FAULT_DATA_RESULT WHERE EQUIP_TYPE = 1) AS JLGZTZ,
(SELECT COUNT(*) FROM DISPATCH.T_FAULT_DATA_RESULT WHERE EQUIP_TYPE = 1 AND FAULT_TYPE = 1) AS DXGZTZ,
(SELECT COUNT(*) FROM DISPATCH.T_FAULT_DATA_RESULT WHERE EQUIP_TYPE = 1 AND FAULT_TYPE = 1 AND ISCH = 1) AS CHCG;
```
这样就避免了多次扫描表,提高了查询效率。
阅读全文