MYSQL update a column with a subtract in a inner join -


i want update column 'pagadas' 'remisiones' calculated value 2 tables. problem i´m not able write subtract inner join.

i´ve got this:

update remisiones r  inner join  ( select remi, sum(cantidad*precio) 'total' detalleremi group remi ) d  on r.id = d.remi  set pagadas = 's' d.total = 250000 

this works too:

update remisiones r  inner join  ( select remisionid, coalesce(sum(cantidadp), 0) 'pagos' pagos  group remisionid ) d  on r.id = d.remisionid  set pagadas = 's' d.pagos = 250000 

but how can subtract total - pagos ?

select remi, sum(cantidad*precio) detalleremi group remi - select remisionid, coalesce(sum(cantidadp), 0) pagos  group remisionid deuda 

and set as:

set pagadas = 's' x.deuda = 0 

is want?

update remisiones r inner join         (select remi, sum(cantidad*precio) total         detalleremi         group remi        ) d         on r.id = d.remi inner join        (select remisionid, coalesce(sum(cantidadp), 0) pagos         pagos          group remisionid        ) p        on r.id = p.remisionid      set pagadas = 's' d.total = p.pagos 

Comments