DROP MATERIALIZED VIEW all_cust_sales_mv;

CREATE MATERIALIZED VIEW all_cust_sales_mv
   BUILD IMMEDIATE
   REFRESH COMPLETE
   ENABLE QUERY REWRITE
   AS
   SELECT c.cust_id, sum(s.amount_sold) AS dollars, p.prod_id,
          sum(s.quantity_sold) as quantity
   FROM   sales s , customers c, products p
   WHERE  c.cust_id = s.cust_id
   AND    s.prod_id = p.prod_id
   GROUP BY c.cust_id, p.prod_id;