city_name | total |
+-----------+-------+
| Bangalore | 13 |
| Mumbai | 21 |
| Coimbatore| 0 |
| Madurai | 0 |
| salem | 0 |
| Chennai | 4 |
| Pune | 30 |
| Ghaziabad | 1 |
| Gurgaon | 2 |
但查詢給出結果:
+-----------+-------+
| city_name | total |
+-----------+-------+
| Bangalore | 13 |
| Mumbai | 21 |
| Chennai | 4 |
| Pune | 30 |
| Ghaziabad | 1 |
| Gurgaon | 2 |
+-----------+-------+
查詢:
select c.city_name,count(distinct r.restaurant_id) as total from restaurants r
left join je_restaurant_status jrs on r.restaurant_id = jrs.restaurant_id
left join locations l on l.location_id = r.location_id
left outer join cities c on c.city_id = l.city_id where jrs.update_date < '2014-10-01 00:00:00'
and jrs.registered=1 and jrs.operations_closed = 0 and jrs.temporary_disabled=1 group by c.city_id
我可以使用哪個函數來包含來自mysql的空值。我希望此查詢與我的其他查詢結果相匹配,以便在將其轉儲到CSV文件時不會發生衝突
也許使用'left join'而不是'inner join'。你可以創建一個[SQLfiddle](http://sqlfiddle.com/)來演示嗎? – showdev 2014-11-14 20:21:26
'有count(distinct r.restaurant_id)> 0' – 2014-11-14 20:22:25
使用了左連接但是相同的結果。 – Torrezzzz 2014-11-14 20:23:29