簡體   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