Mysql 从列中选择顶部值
我怎样才能找到每大洲人口最多的前5个国家。我只想使用下表1: 网址: 数据库: 世界数据库(MyISAM版本,用于MySQL认证和培训) 下面是我的想法:Mysql 从列中选择顶部值,mysql,sql,Mysql,Sql,我怎样才能找到每大洲人口最多的前5个国家。我只想使用下表1: 网址: 数据库: 世界数据库(MyISAM版本,用于MySQL认证和培训) 下面是我的想法: select Continent, substring_index( GROUP_CONCAT(distinct cast(Name as char)), ',', 5) From country group by Continent,Name; 谢谢, Rio这是一个与相关的子查询: SELECT c.name, c.continent
select Continent,
substring_index(
GROUP_CONCAT(distinct cast(Name as char)), ',', 5)
From
country
group by
Continent,Name;
谢谢,
Rio这是一个与
相关的子查询
:
SELECT c.name, c.continent
WHERE population IN (SELECT population
FROM country c1
WHERE c.continent = c1.continent
ORDER by population
LIMIT 5)
FROM country c
由于没有数据库模式,我对它的字段做了一些假设