MySQLネストされたクエリ文

386 ワード

MySQLネストクエリ文は、各省の人口が最も多い都市と最も少ない都市を統計します.
SELECT District,NAME,Population FROM city WHERE Population IN (SELECT MIN(Population) FROM city 
WHERE city.CountryCode='CHN'
GROUP BY city.District)
UNION
SELECT District,NAME,Population FROM city WHERE Population IN (SELECT MAX(Population) FROM city 
WHERE city.CountryCode='CHN'
GROUP BY city.District)