繁体   English   中英

基于2个参数的sql联接表并更新2列

[英]sql join tables based on 2 parameters and update 2 columns

当我想基于1个参数联接2个表并仅更新1列时,我使用以下语法

UPDATE your_table
INNER JOIN your_temp_table on your_temp_table.name= your_table.name
SET your_table.surname= your_temp_table.surname;

但是,如果我想基于2个参数(名称和城市)联接表并更新2列(姓氏和日期)怎么办? 您能帮我找到解决方案吗?

使用逗号设置多个列:

UPDATE your_table
INNER JOIN your_temp_table on your_temp_table.name= your_table.name and 
            your_temp_table.city= your_table.city
SET your_table.surname= your_temp_table.surname,
    your_table.`date`=your_temp_table.`date`;

在表之后from对表和连接语句使用别名。

update yt 
set yt.name='name_value', yt.date= 'date_value' 
from your_table yt
inner join your_temp_table ytt on ytt.surname= yt.surname 
and ytt.City = yt.City

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM