gpt4 book ai didi

php - 从两个有关地理区域的 mysql 表中获取行

转载 作者:行者123 更新时间:2023-11-29 02:58:33 25 4
gpt4 key购买 nike

我有两个表:

邮政编码:id |状态 |地区 |邮政编码(约 40k 条记录)

县:id |状态 |地区 |县(478条记录)

这是示例数据:

zipcodes table

county table

这是来自 phpmyadmin 的两个表的快照: enter image description here这是我尝试过的:

select a.state, a.district,a.zipcode,
b.county from zipcodes a inner join
county b on a.state=b.state and
a.district =b.district

但它会返回大量行,其中每个邮政编码重复 12 次。

州和地区行具有相同的值。我想做的是获取和回显:

状态 |地区 |邮政编码 |县

通过匹配两个表中的州和地区行,因为每个县有多个邮政编码。

我试过在 while 循环中使用 while 循环,但没有用。我也尝试过在选择时使用 JOIN,但它也不正确。

实现这一目标的最佳方法是什么?

最佳答案

select a.state, a.district,a.zipcode,
b.county from zipcodes a inner join
county b on a.state=b.state and
a.district =b.district

关于php - 从两个有关地理区域的 mysql 表中获取行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27436585/

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