0
我有一個表結構如下:MySQL查詢環路組列單查詢
Table1
+----------------+-------------+
| ID | Condition | Color |
+----------------+-------------+
| 1 | FAIR | RED |
+----------------+-------------+
| 2 | GOOD | Red |
+----------------+-------------+
| 3 | Great | BLACK |
+----------------+-------------+
| .. | .. | .. |
+----------------+-------------+
我想對於顏色來算的所有條件。因此,一個簡單的查詢將是:
SELECT COUNT(ID) Total FROM Table1 WHERE Condition="FAIR" AND Color="RED"
這將返回條件爲FAIR且顏色爲紅色的行數。是否有可能包含所有可能的結果?那麼,一個表爲單個查詢提供所有條件的count(id),而不是具有多個查詢?
+----------------+-------------+
| Total | Condition | Color |
+----------------+-------------+
| 5 | FAIR | RED |
+----------------+-------------+
| 6 | FAIR | BLUE |
+----------------+-------------+
| 2 | Great | RED |
+----------------+-------------+
| .. | .. | .. |
+----------------+-------------+
條件和顏色有一組固定值,空值除外。