Table 更新 - 使用一列更新另一列
Table update - use one column to update another
我有一个 table 看起来像这样:
表 1
Val1 Val2 Type Date Key
NULL 110.1 T 11/30/2020 174
NULL 205.5 D 12/31/2020 133
NULL 360.7 T 11/30/2020 190
本例中的键是唯一的。我想要做的是 Set Val1 = Val2 where Type='T' and Date = '11/30/2020'
这看起来正确吗?
Update t1
set t1.Val1 = t2.Val2
From Table1 t1
JOIN Table1 t2
on t1.Key = t2.Key
Where t1.type='T' and t1.Date = '11/30/2020'
期望的结果:
Val1 Val2 Type Date Key
110.1 110.1 T 11/30/2020 174
NULL 205.5 D 12/31/2020 133
360.7 360.7 T 11/30/2020 190
我认为你不需要 join
:
update table1
Set Val1 = Val2
where Type='T' and Date = '2020-11-30';
注意:我建议使用标准格式的日期,这样会枯萎 '2020-11-30'
或 '20201130'
。
我有一个 table 看起来像这样:
表 1
Val1 Val2 Type Date Key
NULL 110.1 T 11/30/2020 174
NULL 205.5 D 12/31/2020 133
NULL 360.7 T 11/30/2020 190
本例中的键是唯一的。我想要做的是 Set Val1 = Val2 where Type='T' and Date = '11/30/2020'
这看起来正确吗?
Update t1
set t1.Val1 = t2.Val2
From Table1 t1
JOIN Table1 t2
on t1.Key = t2.Key
Where t1.type='T' and t1.Date = '11/30/2020'
期望的结果:
Val1 Val2 Type Date Key
110.1 110.1 T 11/30/2020 174
NULL 205.5 D 12/31/2020 133
360.7 360.7 T 11/30/2020 190
我认为你不需要 join
:
update table1
Set Val1 = Val2
where Type='T' and Date = '2020-11-30';
注意:我建议使用标准格式的日期,这样会枯萎 '2020-11-30'
或 '20201130'
。