简体   繁体   中英

create a computed SQL column that maintains the running total orders each customer has

I thought about using a trigger or function to solve the problem but I don't really know how to go about coding it. Any help would be much appreciated.

did you try to create view? view update every time a new row added or updated. Views serve as query and look like a table.

IMHO you should not persist the running totals, the possibility of the value becoming stale is high, instead you should go the route of View as suggested by @m-farhan. Still if you would want to persist the running total, then Trigger would be the safest bet. The Trigger ideally should fire a SQL query to accumulate the Customer's total and update the Total's column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM