【问题标题】:matching 2 column in different tables and replace one of them with a 3rd column匹配不同表中的 2 列,并用第 3 列替换其中之一
【发布时间】:2016-06-01 10:08:09
【问题描述】:

我有带有这些列的表 dbo.Patient

PatientID | Name | DOB 

和另一个表 dbo.Studies 与这些列

PatientID | AccessionNumber

PatientId 在两个表之间是通用的,但我想创建一个查询,在两个表之间匹配 PatientID 后,用研究表中的 AccessionNumber 替换 Patient 表中的 PAtientID。

我该怎么做?

【问题讨论】:

  • 请提供样本数据和输出
  • 为什么需要匹配患者中的患者ID? UPDATE studies SET AsseccionNumber=? WHERE PatientID=? 不够吗?

标签: mysql sql sql-server


【解决方案1】:

试试这个..

update Patient 
set Patient.PatientId =  Studies.AccessionNumber 
from Patient inner join Studies
on Patient.PatientId =  Studies.PatientId;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 2018-09-21
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    相关资源
    最近更新 更多