我目前有一個(gè)new_funeralhomes如下表,其中包含我希望添加到另一個(gè)表中的新數(shù)據(jù):在該表中,我可以輕松地將地址、郵政、電話、網(wǎng)站和電子郵件發(fā)送到該表addressTest:然而,正如您在表中看到的那樣new_funeralhomes,城市/州是文本值,在第二個(gè)表 ( addressTest) 中它們是連接到這些表的 int 值:city:province:我將如何使用addressTest新的城市和省份更新表格?iid 和 id 值匹配并且始終相同。我對(duì)此較新,因此將不勝感激,謝謝。
1 回答

皈依舞
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊
您似乎在尋找insert ... select 帶有joins 的語句。邏輯是:
insert into addressTest
(address, province, postcalcode, city, primaryphone, secondaryphoe, website)
select
n.address
p.id,
n.postcal,
c.id,
n.phone,
n.phone2,
n.website
from new_funeralhomes n
inner join city c on c.name = n.city
inner join province p on p.name = n.state
旁注:源表的列數(shù)似乎少于目標(biāo)表;我為似乎匹配的列調(diào)整了列列表 - 您可能需要查看它以使其正確符合您的要求(但邏輯join,這是您問題的核心,保持不變)。
- 1 回答
- 0 關(guān)注
- 160 瀏覽
添加回答
舉報(bào)
0/150
提交
取消