Question: Assignment 9-7: Updating Summary Data Tables The Brewbean's owner uses several summary sales data tables every day to monitor business activity. The BB_SALES_SUM table holds
Assignment 9-7: Updating Summary Data Tables The Brewbean's owner uses several summary sales data tables every day to monitor business activity. The BB_SALES_SUM table holds the product ID, total sales in dollars, and total quantity sold for each product. A trigger is needed so that every time an order is confirmed or the ORDERPLACED column is updated to 1, the BB_SALES_SUM table is updated accordingly. Create a trigger named BB_SALESUM_TRG that perform this task. Before testing, reset the ORDERPLACED column to 0 for basket 3, as shown in the following code, and use this basket to test the trigger.
This is what I have so far, am i on the right path? is this better?
CREATE OR REPLACE TRIGGER BB_SALESUM_TRG
AFTER UPDATE OF orderplaced ON BB_BASKET
FOR EACH ROW
WHEN (new.orderplaced = 1)
BEGIN INSERT INTO bb_sales_sum(idproduct, tot_sales, tot_qty number)
SELECT idproduct, sum(b.total), sum(b.quantity)
FROM bb_basket b INNER JOIN bb_basketitem bi ON b.idbasket = bi.idbasket
WHERE b.idbasket = :new.idbasket
GROUP BY idproduct END;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
