SUB TOTAL WITH MULTIPLE TABLE

I want to show the subtotals of each product name and maybe the commands I made are useless,
is there any suggestions for me

I have 3 tables

select ORDERS.ORDER_NUM, PRODUCT.PRODUCT_ID, PRODUCT.PRODUCT_NAME, ORDER_DETAILS.QUANTITY, 
ORDER_DETAILS.UNIT_PRICE, sum(ORDER_DETAILS.UNIT_PRICE) as SUBTOTAL from ORDER_DETAILS inner join 
ORDERS on ORDER_DETAILS.ORDER_NUM = ORDERS.ORDER_NUM inner join PRODUCT on ORDER_DETAILS.PRODUCT_ID = 
PRODUCT.PRODUCT_ID group by ORDER_DETAILS.ITEM_NUM order by PRODUCT.PRODUCT_NAME;

+-----------+------------+--------------+----------+------------+----------+
| ORDER_NUM | PRODUCT_ID | PRODUCT_NAME | QUANTITY | UNIT_PRICE | SUBTOTAL |
+-----------+------------+--------------+----------+------------+----------+
|      3004 |       2001 | BEER         | 10       | 160,000    |      160 |
|      3012 |       2001 | BEER         | 5        | 160,000    |      160 |
|      3002 |       2005 | CAKE         | 5        | 50,000     |       50 |
|      3001 |       2004 | CIGARETTE    | 2        | 25,000     |       25 |
|      3011 |       2004 | CIGARETTE    | 5        | 25,000     |       25 |
|      3005 |       2007 | ICE CREAM    | 50       | 10,000     |       10 |
|      3007 |       2010 | MILK         | 3        | 45,000     |       45 |
|      3010 |       2010 | MILK         | 7        | 12,000     |       12 |
|      3008 |       2008 | NOODLES      | 1        | 5,000      |        5 |
|      3013 |       2006 | SODA         | 50       | 12,000     |       12 |
|      3009 |       2002 | WINE         | 1        | 200,000    |      200 |
|      3003 |       2002 | WINE         | 2        | 200,000    |      200 |
|      3006 |       2002 | WINE         | 1        | 200,000    |      200 |
+-----------+------------+--------------+----------+------------+----------+

Product of the Month September 2016

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *