MySQL Forums
Forum List  »  Newbie

Re: How should I initialize a header field from the sum of a detail field?
Posted by: hamid jon
Date: December 05, 2023 11:16PM

To avoid performance issues, you should not attempt to calculate the sum in the application layer. Instead, you can use a trigger to update the invoices.itemSalesAmount field whenever the invoicedetails table is modified. The trigger should calculate the sum of invoicedetails.totalLineAmount for all records where invoicedetails.historySequenceNumber = invoices.historySequenceNumber and invoicedetails.itemNumber does not begin with '/' or '&'.

Options: ReplyQuote


Subject
Written By
Posted
Re: How should I initialize a header field from the sum of a detail field?
December 05, 2023 11:16PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.