我已经开始学习MySQL。
这是表格world:
world
+-------------+-----------+---------+ | name | continent | area | +-------------+-----------+---------+ | Afghanistan | Asia | 652230 | | Albania | Europe | 2831741 | | Algeria | Africa | 28748 | | ... | ... | ... | +-------------+-----------+---------+
我需要:
列出每个大洲以及按字母顺序排在首位的国家/地区的名称
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