[Resumen de actualización de SQL de métodos de actualización de asociación de múltiples tablas]

1. MySQL

update test1,test2 
set test1.name=test2.name,test1.age=test2.age
where test1.id=test2.id

2. oráculo

1. Asociación de varias tablas, actualice un determinado campo EX1 en toda la tabla
:

UPDATE REDREPORT T  SET T.SSHY=(SELECT  D.SSHY FROM DATA_COMPANY D WHERE T.DWDM =D.DWDM 
and rownum=1 );

EJ2:

update test1 
set (test1.name,test1.age)=
(select test2.name,test2.age from test2 where test2.id=test1.id)

2. Asociación de varias tablas, actualice un determinado campo de la fila especificada

UPDATE "DATA_HISTORY_copy2" t 
set SHJG = (select m.SHJG from DATA_MONTHCOPY m where t.DWDM = m.DWDM and SUBSTR(t.SQSJ, 0, 8) = SUBSTR(m.SQSJ, 0, 8)) 
WHERE EXISTS (select t.* from "DATA_HISTORY_copy2" t,DATA_MONTHCOPY m where t.DWDM = m.DWDM and SUBSTR(t.SQSJ, 0, 8) = SUBSTR(m.SQSJ, 0, 8))

3. Servidor SQL

update test1
set test1.name=test2.name,test1.age=test2.age
from test1 
inner join test2
on test1.id=test2.id

4. Método común

update test1 
set name=(select name from test2 where test2.id=test1.id),
age=(select age from test2 where test2.id=test1.id)

Cita

[SQL] Actualización de SQL Resumen de los métodos de actualización de asociaciones de múltiples tablas .

Supongo que te gusta

Origin blog.csdn.net/m0_46459413/article/details/124261628
Recomendado
Clasificación