有共通條件的SQL式合併問題

迷路
SELECT COUNT(*) FROM `tableA` WHERE `ID`=xxx AND `DT`>='2020-02-01' AND `DT`<='2020-02-29';
取得總數
SELECT COUNT(*) FROM `tableA` WHERE `ID`=xxx AND `DT`>='2020-02-01' AND `DT`<='2020-02-29' AND `TypeA`=1;
取得條件一的總數
SELECT COUNT(*) FROM `tableA` WHERE `ID`=xxx AND `DT`>='2020-02-01' AND `DT`<='2020-02-29' AND `TypeB`=1;
取得條件二的總數
SELECT COUNT(*) FROM `tableA` WHERE `ID`=xxx AND `DT`>='2020-02-01' AND `DT`<='2020-02-29' AND `TypeA`=0 AND `TypeB`=0 AND `Kind`='abc' AND `Class`='def';
取得條件三的總數
SELECT SUM(`Number`) FROM `tableA` WHERE `ID`=xxx AND `DT`>='2020-02-01' AND `DT`<='2020-02-29';
取得欄位的總和
同一張表,並且都有共通條件限制,是否能將這些SQL式合併,加快處理速度
回到頂部