SQL从2个表插入数据

2024-10-02 02:40:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个表,postcodelatlngbranch

postcodelatlng

^{tb1}$

branch

^{tb2}$

我正在尝试创建一个新表,它为branch中的每个邮政编码列出postcodelatlng中的每个邮政编码

New table

^{tb3}$

我曾尝试用Python和Pandas和SQLAlchemy来实现这一点,但我无法理解这一点,所以我认为用SQL来实现这一点可能更容易,但我也坚持了这一点

lat/lng数据仅保存在postcodelatlng中,但可以手动将其添加到branch表中(那里只有42个唯一的邮政编码(某些分支共享一个邮政编码))

我在{}有120条记录,42个独特的邮政编码,在{}有1778786条记录


Tags: 数据branchpandasnewsqlsqlalchemy记录table
1条回答
网友
1楼 · 发布于 2024-10-02 02:40:27

通过无条件联接,达到了所需的表,但我不知道from_lat和from_lng的值

insert into newtable
select b.postcode,p.postcode,"from_lat = ?","from_lng = ?",p.lat,p.lng
from branch b join postcodelatlng p on 1 = 1

或交叉连接

insert into newtable
select b.postcode,p.postcode,"from_lat = ?","from_lng = ?",p.lat,p.lng
from branch b cross join postcodelatlng p

相关问题 更多 >

    热门问题