Write SQL code that could be used from these seven tables below 12. List the ful
ID: 3699450 • Letter: W
Question
Write SQL code that could be used from these seven tables below
12. List the full name and number of different parts for each order each customer has placed.
Rename the calculated column as TOTAL_PARTS.
13. List the order date of an order containing a part description with letter D (or d) in it.
14. List the customer name of those who purchased products with a unit price of more than $150.
15. List sales representative number and the number of customers handled by each sales
representative who got paid at most as the average total commission. Rename the number of
transactions as NO_Customers
Table: PART Column Data Type gth Precision Scale Nullable PART NUMBER PART DESCRIPTION UNITS ON HAND ITEM CLASS WAREHOUSE NUMBERNUMBER UNIT PRICE VARCHAR2 VARCHAR2 NUMBER CHAR No - Yes Yes - Yes Yes 2 Yes 12 NUMBE 7Explanation / Answer
/*12. List the full name and number of different parts
for each order each customer has placed.
Rename the calculated column as TOTAL_PARTS.*/
SELECT (c.CLAST+' '+c.CFIRST) AS Name,COUNT(ol.PART_NUMBER) AS TOTAL_PARTS
FROM CUSTOMER c INNER JOIN ORDERS o ON c.C_NUMBER=o.C_NUMBER
INNER JOIN ORDER_LINE ol ON o.ORDER_NUMBER=ol.ORDER_NUMBER
GROUP BY c.C_NUMBER,o.ORDER_NUMBER
/*13. List the order date of an order containing a part
description with letter D (or d) in it.*/
SELECT o.ORDER_DATE FROM ORDERS o INNER JOIN
ORDER_LINE ol ON o.ORDER_NUMBER=ol.ORDER_NUMBER
INNER JOIN PART p ON ol.PART_NUMBER=p.PART_NUMBER
WHERE p.PART_DESCRIPTION LIKE '%d%';
/*14. List the customer name of those who purchased
products with a unit price of more than $150.*/
SELECT (c.CLAST+' '+c.CFIRST) AS Name
FROM CUSTOMER c INNER JOIN ORDERS o ON c.C_NUMBER=o.C_NUMBER
INNER JOIN ORDER_LINE ol ON o.ORDER_NUMBER=ol.ORDER_NUMBER
INNER JOIN PART p ON ol.PART_NUMBER=p.PART_NUMBER
WHERE p.UNIT_PRICE>150;
/*15. List sales representative number and
the number of customers handled by each sales
representative who got paid at most as the
average total commission. Rename the number of
transactions as NO_Customers*/
SELECT c.SLSREP_NUMBER,COUNT(c.C_NUMBER) AS NumberOfCustomers
FROM CUSTOMER c INNER JOIN SALES_REP s
ON c.SLSREP_NUMBER=s.SLSREP_NUMBER
WHERE s.TOTAL_COMMISSION >= (SELECT AVG(TOTAL_COMMISSION) FROM SALES_REP)
GROUP BY c.SLSREP_NUMBER;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.