在sql中过滤列

时间:2016-06-25 23:30:42

标签: mysql sql

从这里可用的世界数据库http://downloads.mysql.com/docs/world.sql.gz我想只显示说超过5种语言的国家/地区的名称:

我试过这个:

SELECT 
    country.Name, COUNT(countrylanguage.Language) as languages
FROM 
    country, countrylanguage
WHERE 
    country.Code = countrylanguage.CountryCode 
GROUP BY 
    country.Name
HAVING 
    languages >= 6

但问题是,它是否也显示了语言的数量,我想要的只是列country.Name

谢谢。

2 个答案:

答案 0 :(得分:1)

以下是TinTran评论的答案:

SELECT country.Name FROM country, countrylanguage WHERE country.Code = countrylanguage.CountryCode Group BY country.Name HAVING COUNT(countrylanguage.Language) >= 6

答案 1 :(得分:1)

使用ANSI样式INNER JOIN。

SELECT country.Name
FROM country INNER JOIN countrylanguage
ON country.Code = countrylanguage.CountryCode 
Group BY country.Name
HAVING COUNT(countrylanguage.Language) >= 6