Write SQL code that could be used from these seven tables below 12. List the ful
ID: 3699406 • 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) Aggregate function SUM is used with GROUP BY clause to find the number of ordered parts for each customer placing order. 3 tables namely CUSTOMER, ORDERS and ORDER_LINE are joined to get the result.
SELECT c.CLAST, c.CFIRST, SUM(ol.NUMBER_ORDERED) AS "Total_Parts"
FROM CUSTOMER c
INNER JOIN ORDERS o
ON o.C_NUMBER = c.C_NUMBER
INNER JOIN ORDER_LINE ol
ON ol.ORDER_NUMBER = o.ORDER_NUMBER
GROUP BY c.CLAST, c.CFIRST;
13) ORDER_DATE of all the parts whose description starts with 'D'. For this in WHERE clause wild card is used with LIKE clause.
SELECT ORDER_DATE
FROM ORDER o
INNER JOIN ORDER_LINE ol
ON o.ORDER_NUMBER = ol.ORDER_NUMBER
INNER JOIN PART p
ON p.PART_NUMBER = ol.PART_NUMBER
WHERE p.PART_DESCRIPTION LIKE 'D%';
14) For this 4 tables namely CUSTOMER, ORDERS, ORDER_LINE and PART are joined. In where clause Unit_Price > 150 is filtered out.
SELECT DISTINCT c.CLAST, c.CFIRST
FROM CUSTOMER c
INNER JOIN ORDERS o
ON o.C_NUMBER = c.C_NUMBER
INNER JOIN ORDER_LINE ol
ON ol.ORDER_NUMBER = o.ORDER_NUMBER
INNER JOIN PART p
ON p.PART_NUMBER = ol.PART_NUMBER
WHERE p.UNIT_PRICE > 150;
15) Subquery is used in where clause to compare the Commission_rate of each sales representative with the average commission.
SELECT sr.SLSREP_NUMBER, COUNT(c.C_NUMBER) AS "NO_Customers"
FROM SALES_REP sr
INNER JOIN CUSTOMER c
ON c.C_NUMBER = sr.C_NUMBER
WHERE sr.COMMISSION_RATE > (SELECT AVG(COMMISSION_RATE) FROM SALES_REP)
GROUP BY sr.SLSREP_NUMBER;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.