如何获取0作为计数输出?

kxe2p93d  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(363)
SELECT Country.NAME, COUNT(City.NAME) as Number_of_cities
FROM City
JOIN Country ON City.COUNTRY = Country.CODE
WHERE City.LONGITUDE IS NULL AND City.LATITUDE IS NULL
GROUP BY Country.NAME, City.COUNTRY;

就像现在的代码一样,没有显示那些只有长宽值城市的国家。我该如何更改代码,以便所有城市都有长距离和纬度值的国家将0显示为coun?

xhv8bpkk

xhv8bpkk1#

你想要一个 left join ,在 on 条款:

SELECT co.NAME, COUNT(ci.country) as Number_of_cities
FROM country co left join
     City ci
     ON ci.COUNTRY = co.CODE and
        ci.LONGITUDE IS NULL and
        ci.LATITUDE IS NULL
GROUP BY co.NAME;

相关问题