再會,
我對 MySQL 還很陌生,我一直在研究它。我一直在關注一個使用 5.X 版的非常古老的教程。我在我的虛擬機上使用 8.0.29 版。使用示例世界資料庫,我在使用下面的查詢按大陸分組時遇到問題。
SELECT Continent, Region, SUM(Popuilation) AS TotalPop FROM country GROUP BY Contient, Region;
--------------- --------------------------- ------------
| Continent | Region | TotalPop |
--------------- --------------------------- ------------
| North America | Caribbean | 38140000 |
| Asia | Southern and Central Asia | 1490776000 |
| Africa | Central Africa | 95652000 |
| Europe | Southern Europe | 144674200 |
| Asia | Middle East | 188380700 |
| South America | South America | 345780000 |
| Oceania | Polynesia | 633050 |
| Antarctica | Antarctica | 0 |
| Oceania | Australia and New Zealand | 22753100 |
| Europe | Western Europe | 183247600 |
| Africa | Eastern Africa | 246999000 |
| Africa | Western Africa | 221672000 |
| Europe | Eastern Europe | 307026000 |
| North America | Central America | 135221000 |
| North America | North America | 309632000 |
| Asia | Southeast Asia | 518541000 |
| Africa | Southern Africa | 46886000 |
| Asia | Eastern Asia | 1507328000 |
| Europe | Nordic Countries | 24166400 |
| Africa | Northern Africa | 173266000 |
| Europe | Baltic Countries | 7561900 |
| Oceania | Melanesia | 6472000 |
| Oceania | Micronesia | 543000 |
| Europe | British Islands | 63398500 |
| Oceania | Micronesia/Caribbean | 0 |
--------------- --------------------------- ------------
25 rows in set (0.00 sec)
我做錯了什么?VTC 教程顯示大陸被很好地分組。
我真的為我在這個話題上的菜鳥提前道歉......
uj5u.com熱心網友回復:
您的查詢是正確的,除了Contient. 但是,如果您希望按照大洲對結果集進行排序,則必須在查詢中添加 order by 子句。
SELECT Continent, Region, SUM(Population) as TotalPop
FROM country
GROUP BY Continent, Region
ORDER BY Continent, Region;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/484597.html
上一篇:MYSQL左連接包括不存在的行
