[英]Updating SQL table converting varchar to int
我目前有一個如下表new_funeralhomes
,其中包含我希望添加到另一個表的新數據:
,
在該表中,我可以輕松地將地址、郵政、電話、網站和 email 發送到該表addressTest
:
.
但是,正如您在new_funeralhomes
表中看到的那樣,城市/州是文本值,在第二個表( addressTest
)中它們是連接到這些表的 int 值:
city
:
,
province
:
.
我將如何使用新的城市和省份更新addressTest
表? iid 和 id 值匹配並且始終相同。
我對此較新,因此將不勝感激,謝謝。
您似乎正在尋找insert... select
帶有join
的語句。 邏輯是:
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
旁注:源表的列數似乎少於目標表; 我為似乎匹配的列調整了列列表 - 您可能需要查看它,以便它正確匹配您的要求(但join
邏輯,這是您問題的核心,保持不變)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.