MySQL-选择按字母顺序排列的名字 [英] MySQL - SELECT the name that comes first alphabetically
本文介绍了MySQL-选择按字母顺序排列的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开始学习MySQL.
I have started to learn 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的结果必须是:
The result of SELECT must be:
+---------------+---------------------+
| 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-选择按字母顺序排列的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文