I have a table called salesinvoiceitems that contains fields as
- invoiceNumber
- name
- qty
- rate
- ledgerId
And a balance table with fields as
- invoiceNumber
- ledgerId
- amount
In the balance table I have all the rows containing the invoice numbers. I want to update the amount from salesinvoiceitems table. Amount needs to be calculated as follows:
SUM OF (RATE X QTY) for all the rows of one invoice from salesinvoicetable.
I have tried this but not working:
INSERT INTO balancetable (ledgerId,invoiceNumber,date,company,triggerredby)
SELECT buyerId,invoiceNumber,invoiceDate,company,"salesinvoices" as triggerredby
FROM salesinvoices
Please shed some light.