我有这两个表,我想要比较它们,以了解表2中是否有空值,如果有,则将表1中的现有值替换为表2中的空值(用作为主键的代码列)。
Table 1
Code Name Points
1 Juan Perez 10
2 Marco Salgado 5
3 Carlos Soto 9
4 Alberto Ruiz 12
5 Alejandro Castro 5
10 Jonatan Polanco 0
11 JD NULL
Table 2
Code Name Points
1 Juan Perez 10
2 Marco Salgado 5
3 Carlos Soto 9
4 Alberto Ruiz 12
5 Alejandro Castro 5
10 Null 0
11 JD 9生成的表应该如下所示
Table 2
Code Name Points
1 Juan Perez 10
2 Marco Salgado 5
3 Carlos Soto 9
4 Alberto Ruiz 12
5 Alejandro Castro 5
10 Jonatan Polanco 0
11 JD 9发布于 2021-12-23 00:54:04
如果您试图更新在Point列中具有空值的行,则只需连接这两个表并添加where子句,将行限制为要更新的行。就像这样
UPDATE t2
SET Points = t.Points
FROM table_1 t
JOIN table_2 t2
ON t.code = t2.code
WHERE t2.Points IS NULL https://stackoverflow.com/questions/70456457
复制相似问题