SQL>
SQL>
SQL> create table sale(
2 gift_id integer
3 ,product_id integer
4 ,quantity number(4,0)
5 ,price number(7,2)
6 ,primary key (gift_id ,product_id)
7 );
Table created.
SQL>
SQL> -- order_item table inserts
SQL> insert into sale(gift_id, product_id, quantity, price) values(1, 2, 10, 23.00 );
1 row created.
SQL> insert into sale(gift_id, product_id, quantity, price) values(2, 1, 1, 23.11 );
1 row created.
SQL>
SQL>
SQL> select product_id, sum(quantity) "TOTAL SOLD",
2 sum(price * quantity) "GROSS $"
3 from sale
4 group by product_id;
PRODUCT_ID TOTAL SOLD GROSS $
---------- ---------- ----------
1 1 23.11
2 10 230
2 rows selected.
SQL>
SQL>
SQL> drop table sale;
Table dropped.
|