【问题标题】:how to add column to the table from another table by join如何通过连接将列从另一个表添加到表中
【发布时间】:2017-03-05 23:38:49
【问题描述】:

我想通过连接从另一个表中添加列。 我希望用另一个表中的一列更新初始表。当我这样做时,它返回我 SQL 命令没有正确结束。 我有一个问题:

update final_tableau 
set final_tableau.Mobile_flag = credit_mobile.Mobile_flag
from final_tableau a left join credit_mobile b 
on a.client_pin = b.client_pin

【问题讨论】:

  • 标记 RDBMS。你不想添加列,你想更新字段值,这是完全不同的。尝试在更新语句中使用别名,例如a.Mobile_flag = b.Mobile_flag
  • 试试我的解决方案,请回复
  • 知道了!刚刚列出了我需要的引脚并在那里插入了值

标签: sql join rdbms create-table


【解决方案1】:

试试这个

update final_tableau
  set Mobile_flag= (
               select credit_mobile.Mobile_flag
                 from credit_mobile
                where credit_mobile.client_pin= final_tableau.client_pin
              )
 where exists (
               select * 
                 from credit_mobile
                where credit_mobile.client_pin= final_tableau.client_pin
              );

【讨论】:

    【解决方案2】:

    试试这个:

    Alter table A add column3 datatype
    update A 
    set column3 = B.column3 
    from A inner join B on A.Column1 = B.Column2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2021-01-11
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多