Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 从列中选择顶部值_Mysql_Sql - Fatal编程技术网

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

我怎样才能找到每大洲人口最多的前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 
WHERE population IN (SELECT population 
                    FROM country c1
                    WHERE c.continent = c1.continent
                    ORDER by population
                    LIMIT 5)
FROM country c
由于没有数据库模式,我对它的字段做了一些假设