0

我想到了。SELECT DISTINCT ON (country.name) country.name AS country... 工作

我正在查询每个国家/地区的最大城市(就人口而言)。问题是给定国家/地区的某些城市的人口数量相同,因此查询返回的每个国家/地区不止一个城市。(我试过 SELECT DISTINCT country.name,但它给了我相同的输出)

有任何想法吗?

这是我的代码:

        $query = "SELECT country.name AS country, largest_city, sq.pop AS population
        FROM lab6.country INNER JOIN 

        (SELECT MAX(city.population) AS pop, country_code 
        FROM lab6.city 
        GROUP BY country_code) AS sq
        USING (country_code)

        INNER JOIN

        (SELECT city.name AS largest_city, city.population
        FROM lab6.city) AS sq1
        ON (sq1.population = sq.pop)

        ORDER BY country.name ASC";
4

1 回答 1

1

每个 OP:

我想到了。SELECT DISTINCT ON (country.name) country.name AS country... 工作

现在我们可以看到这个问题在没有打开问题的情况下有答案。

于 2013-10-04T20:08:56.747 回答