【发布时间】:2019-09-17 05:39:29
【问题描述】:
我有一张带有 Patient_id、surgical_dt(Table1) 的表格。我需要插入从 (Table2) 到 (Table3) 的所有体重、身高详细信息,其中 Table2.date 在 6 个月的手术时间前后落下。
我与您分享我尝试过的代码。但它返回: “无法绑定多部分标识符“b.Sur_dt”。”
请提出一些解决问题的想法。 提前致谢!
select a.patient_id,a.Record_Date,a.Height,a.Weight,a.Waist,a.hip into Table3 from Table2 a
where a.Record_Date between b.Sur_dt-180 and b.Sur_dt+180 and a.Patient_id in (select b.Patient_id from Table1 b where a.patient_id = b.patient_id)
【问题讨论】:
-
b的表别名在您的主SELECT查询中不可访问。由于WHERE IN()是作为子查询执行的,因此您需要使用JOIN来建立别名。