數據庫表這樣返回計數0與MySQL組由
============================
= suburb_id | value
= 1 | 2
= 1 | 3
= 2 | 4
= 3 | 5
查詢
SELECT COUNT(suburb_id) AS total, suburb_id
FROM suburbs
where suburb_id IN (1,2,3,4)
GROUP BY suburb_id
然而,當我運行此查詢,它並沒有給COUNT(suburb_id)= 0時suburb_id = 0 因爲在郊區表,沒有suburb_id 4,我想這個查詢爲suburb_id = 4返回0,像
============================
= total | suburb_id
= 2 | 1
= 1 | 2
= 1 | 3
= 0 | 4
你是否有另一張桌子,提供所有郊區的信息?或者是surburb 4 Sir Not-In-In-This-Database? – Powerlord 2010-08-30 14:06:50