you will use the my_guitar_shop database to answer the questions in this assignm
ID: 3588133 • Letter: Y
Question
you will use the my_guitar_shop databaseto answer the questions in this assignment. Please download the script file https://www.dropbox.com/s/o966abkh72nc3sn/create_my_guitar_shop.sql?dl=0 and build the database on your server before starting your work on the questions if you have not already done so. Please contact the instructors if you encounter problems downloading or running the database script.
You may lose points if you use more than one query for each of questions 1, 2, 3, 5, and 6, and more than two queries for question 4.
For this assignment, you are not allowed to use the LIMIT keyword to filter result rows in any of yourSELECT queries. You may lose points if you do so.
For this assignment, you are not allowed to use exact match conditions to filter result rows in any of your SELECT queries. For example, you cannot use
... WHERE last_name=”Smith”... in a SELECT query. You may lose points if you do so.
Explanation / Answer
Hi,
As you have not shared the columns list for the Product and order_Items table, I assume we have a product_id in both of these tables. Please replace the column names with the exact table names of your database.
Query-
SELECT P.PRODUCT_NAME,SUM((ITEM_PRICE-DISCOUNT)*QUANTITY) AS PRODUCT_TOTAL FROM PRODUCT P JOIN ORDER_ITEMS OI
ON P.PRODUCT_ID=OI.PRODUCT_ID
GROUP BY P.PRODUCT;
UNION ALL
SELECT NULL AS PRODUCT_NAME, SUM(PRODUCT_TOTAL) AS PRODUCT_TOTAL FROM(SELECT P.PRODUCT_NAME,SUM((ITEM_PRICE-DISCOUNT)*QUANTITY) AS PRODUCT_TOTAL FROM PRODUCT P JOIN ORDER_ITEMS OI
ON P.PRODUCT_ID=OI.PRODUCT_ID
GROUP BY P.PRODUCT);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.