gpt4 book ai didi

mysql - 基于特定 SQL 组的列表

转载 作者:行者123 更新时间:2023-11-29 01:37:21 25 4
gpt4 key购买 nike

如何从下表中列出表面积大于同一地区所有其他国家的所有国家的名称:

+----------------------------------------------+---------------------------+-------------+
| name | region | surfacearea |
+----------------------------------------------+---------------------------+-------------+
| Aruba | Caribbean | 193.00 |
| Afghanistan | Southern and Central Asia | 652090.00 |
| Angola | Central Africa | 1246700.00 |
| Anguilla | Caribbean | 96.00 |
| Albania | Southern Europe | 28748.00 |
| Andorra | Southern Europe | 468.00 |
| Netherlands Antilles | Caribbean | 800.00 |

到目前为止,我已经获得了这段代码,但它没有列出国家?这段代码正确吗?

select region, max(surfacearea) as maxArea 
from country
group by region;

最佳答案

可能是您可以对临时表使用内部联接

 select name from 
country as a
inner join
( select region, max(surfacearea) as maxarea
from country
group by region ) as t on a.region = t.region
where a.surfacearea = t.maxarea;

关于mysql - 基于特定 SQL 组的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333390/

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