缺少列结果(应该很容易修复)

时间:2014-03-09 22:58:04

标签: sql postgresql

出于某种原因,这只会返回正确的相应城市并计入国家/地区,但拒绝退回国家/地区列。第二列和第三列返回左移一。结果是正确的,就在我调用SELECT country.name时,这个字段没有返回。

SELECT
  country.name,
  city.name,
  COUNT(country_language.language) AS count
FROM
  lab6.country,
  lab6.city,
  lab6.country_language
GROUP BY
  country.name,
  country.country_code,
  country_language.country_code,
  city.name,
  city.id
HAVING
  COUNT(country_language.language) >= 8 AND
  COUNT(country_language.language) <= 12 AND
  country.country_code = country_language.country_code AND
  country.capital = city.id

1 个答案:

答案 0 :(得分:1)

您很可能需要为其中一个名称列添加别名,如下所示:

SELECT
  country.name,
  city.name as city_name,
  COUNT(country_language.language) AS count
  ...