gpt4 book ai didi

MySQL 返回最低的邮政编码

转载 作者:行者123 更新时间:2023-11-29 04:12:17 25 4
gpt4 key购买 nike

得到这个 SQL:

SELECT DISTINCT(LocCity), LocZipCode FROM exp_course_events order by LocCity

和这个数据:

INSERT INTO `exp_course_events` (`LocCity`, `LocZipCode`) VALUES 
('Aguadilla', '00602'), ('Akron', '44300'),('Akron', '44333'),
('Albany', '12205'), ('Albuquerque', '87102'),
('Albuquerque', '87109'), ('Austin', '78741'),
('Austin', '78753'), ('Austin', '78757'),
('Bend', '97701'), ('San Antonio', '78200'),
('San Antonio', '78201'),
....
('San Antonio', '78207');

只需要为每个 LocCity 返回一个 LocZipCode 值,最好是最小的 LocZipCode对于那个 LocCity。

这是我想要的结果:

Aguadilla, 00602
Akron, 44300
Albany, 12205
Albuquerque, 87102
Austin, 78741
Bend, 97701
San Antonio, 78200
San Diego, 92108
San Francisco, 94111
San Juan, 00926
Santa Clara (San Jose), 95054
Springdale, 72762
Springfield, 62703
St. Louis. 63105
Visalia, 993291
Waco, 76705
Warwick, 02886
Waukesha, 53186
West Chester, 45069
West Des Moines, 50300

最佳答案

SELECT LocCity, MIN(LocZipCode) 
FROM exp_course_events
GROUP BY LocCity
ORDER BY LocCity

了解 GROUP BY子句在这里。

关于MySQL 返回最低的邮政编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7150769/

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