多个值更新到新表中

时间:2018-03-17 23:32:56

标签: sql oracle sql-update

     4            7.99          31.96           10

发票

i_invoicenumber i_invoicedate i_payment i_emailaddress i_subtotal

         50       06-FEB-18 Cash         40      John@test

2 个答案:

答案 0 :(得分:1)

在Oracle中,您可以使用子查询:

update invoice i
    set subtotal = (select sum(li.li_total)
                    from line_item li
                    where i.invoice_number = li.invoice_number
                   );

答案 1 :(得分:0)

试一试......

UPDATE invoice i 
INNER JOIN
(
   SELECT invoice_number, sum(total) as line_item_total
   FROM line_item
   GROUP BY invoice_number
) li ON i.invoice_number = li.invoice_number
SET i.subtotal = li.line_item_total