我有以下查询:为什么这个查询使用UNION ALL不工作
SELECT a.status, count(a.status) FROM
(SELECT 'Delivered' AS status
UNION ALL SELECT 'Buffered'
UNION ALL SELECT 'Not Delivered'
UNION ALL SELECT 'Not Reported') a
LEFT JOIN
bulk_sms_numbers
ON a.status = bulk_sms_numbers.delivery_status
WHERE bulk_sms_id = 52
GROUP BY a.status;
,并得到以下结果:
+-----------+-----------------+
| status | count(a.status) |
+-----------+-----------------+
| Buffered | 10 |
| Delivered | 3200 |
+-----------+-----------------+
我想要的结果集包含所有的候选条件中的状态列union all查询
输出我需要的示例。
+---------------+-----------------+
| status | count(a.status) |
+---------------+-----------------+
| Buffered | 10 |
| Delivered | 3200 |
| Not Delieverd | 0 |
| Not Reported | 0 |
+---------------+-----------------+
我使用MySQL
的'WHERE bulk_sms_id = 52'是可能的罪魁祸首...... – PinnyM