我有两个相关的表,data(no, name, citycode, age) 和 city(code, city)
表城
+------+------------+
| code | city |
+------+------------+
| A1 | Jakarta |
| A2 | Bali |
| A3 | Semarang |
| A4 | Surabaya |
| C1 | Dili |
| C2 | Jayapura |
| C3 | Yogyakarta |
| C4 | Bandung |
+------+------------+
表数据
+----+--------+----------+------+
| no | name | citycode | age |
+----+--------+----------+------+
| 1 | Ony | A3 | 27 |
| 2 | Abri | A3 | 28 |
| 3 | Denny | C4 | 27 |
| 4 | Febri | C1 | 27 |
| 5 | Galih | C3 | 28 |
| 6 | Yulia | A2 | 26 |
| 7 | Zening | A1 | 25 |
+----+--------+----------+------+
我想按城市统计 27 岁的员工人数
我的查询:
select city.city , count(data.name) as Nmb_of_employees
from city
left join
data on data.citycode = city.code
where data.age = 27
group by city.city;
结果
+----------+------------------+
| city | Nmb_of_employees |
+----------+------------------+
| Bandung | 1 |
| Dili | 1 |
| Semarang | 1 |
+----------+------------------+
但我想要的结果是这样的
+------------+------------------+
| city | Nmb_of_employees |
+------------+------------------+
| Jakarta | 0 |
| Bali | 0 |
| Semarang | 1 |
| Surabaya | 0 |
| Dili | 1 |
| Jayapura | 0 |
| Yogyakarta | 0 |
| Bandung | 1 |
+------------+------------------+
对于上述结果,我应该使用什么查询?