以下查询给出了结果,但我需要的是:
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的null值。我希望此查询与我的其他查询结果匹配,以便在将其转储到CSV文件
时不会发生冲突答案 0 :(得分:0)
select c.city_name,count(distinct r.restaurant_id) as total from restaurants r
inner join status jrs on r.restaurant_id = jrs.restaurant_id
inner join locations l on l.location_id = r.location_id
right 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
group by c.city_id;