Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   update sum para dos tablas (https://www.clubdelphi.com/foros/showthread.php?t=70888)

ingabraham 17-11-2010 18:39:58

update sum para dos tablas
 
tengo una tabla la cual contiene

tabla1
---------
nrot1
valor1
valor2
valor3
totalt1


tabla2
----
nrot1
valort2

necesito un update que me actualize todos los registros de la tabla1
total1 asi:

total1=valor1+valor2+valor3 + suma(valort2 donde sea igual el nrot1)

Casimiro Noteví 17-11-2010 22:23:34

No dices para qué BD, pero más o menos así:
Código:

update tabla1 set total1=valor1+valor2+valor3+
  (select sum(valor2) from tabla2 where tabla2.nrot1=CODIGO )
where tabla1.nrot1=CODIGO


Caro 17-11-2010 22:54:53

Hola ingabraham, si quieres hacer un update de todos los registros, puedes hacerlo de esta forma:

Código SQL [-]
update t1 set total=valor1+valor2+valor3+(select sum(valort2)
                                          from tabla2
                                          where nrot1=t1.nrot1)

Saluditos


La franja horaria es GMT +2. Ahora son las 13:01:35.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi