繁体   English   中英

从列中选择最高值

[英]Selecting top values from columns

如何找到每个大陆人口最多的前5个国家。 我只想使用下面的1个表:

网址: http//dev.mysql.com/doc/index-other.html

数据库:世界数据库(MyISAM版本,用于MySQL认证和培训)

以下是我的想法:

select Continent,
substring_index(
GROUP_CONCAT(distinct cast(Name as char)), ',', 5)
From
country
group by
Continent,Name;

谢谢,里约热内卢

这是与correlated sub-query

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

没有数据库架构,我对其字段进行了一些假设。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM