gpt4 book ai didi

MySQL - 选择按字母顺序排在第一位的名称

转载 作者:IT老高 更新时间:2023-10-29 00:18:41 25 4
gpt4 key购买 nike

我开始学习MySQL了。

这是表格world:

+-------------+-----------+---------+
| name | continent | area |
+-------------+-----------+---------+
| Afghanistan | Asia | 652230 |
| Albania | Europe | 2831741 |
| Algeria | Africa | 28748 |
| ... | ... | ... |
+-------------+-----------+---------+

我需要:

List each continent and the name of the country that comes first alphabetically

SELECT 的结果必须是:

+---------------+---------------------+
| continent | name |
+---------------+---------------------+
| Africa | Algeria |
| Asia | Afghanistan |
| Caribbean | Antigua and Barbuda |
| Eurasia | Armenia |
| Europe | Albania |
| North America | Belize |
| Oceania | Australia |
| South America | Argentina |
+---------------+---------------------+

最佳答案

这是一个简单的聚合:

SELECT continent, MIN(name) AS name
FROM world
GROUP BY continent
ORDER by continent

关于MySQL - 选择按字母顺序排在第一位的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30231937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com