Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**PLEASE LIST ALL OF THE QUERIES USING SQL/ORACLE FOR THE FOLLOWING STATEMENTS**

ID: 3699346 • Letter: #

Question

**PLEASE LIST ALL OF THE QUERIES USING SQL/ORACLE FOR THE FOLLOWING STATEMENTS** THANK YOU

TABLES TO BE USED

1. List the total number of parts ordered on each day. Rank your results in ascending order on order date.

List the full name and mailing address of customers who placed an order on 04-AUG-2013. If same customer has placed more than one order on this day, only show his/her information once.

List the order date, order number, total quoted price for each order placed between 03-AUG2013 and 06-AUG-2013.

List the average commission rate (rename to AVG_RATE) and the highest total commission (rename to MAX_COMMISSION) of sales representatives who sold SG class items.

List the warehouse number and the total number of orders from each warehouse.

2. List the full name of the sales representatives, order number, and total quoted price for each order (rename to TQP) handled by each sales representative.

List the part number and part description of parts with units on hand higher than the average units on hand across all parts.

List the full name and credit limit of customer who bought a Gas Grill.

List the warehouse number and total dollar amount of all items sold from that warehouse. Rename the calculated column TOTAL_VALUE. TOTAL_VALUE=SUM(NUMBER_ORDERED*QUOTED_PRICE).

3. List the part description of the part with the most units on hand.

List the part description of the part that was sold the most (in terms of total number ordered).

List the full name and number of different parts for each order each customer has placed. Rename the calculated column as TOTAL_PARTS.

List the order date of an order containing a part description with letter D (or d) in it.

4. List the customer name of those who purchased products with a unit price of more than $150.

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.

Tables Rows Last Analyzed lable Name CUSTOMER NEWCUST NEWTAB2 ORDERS ORDER LINE TABLE TABLE TABLE TABLE TABLE TABLE TABLE TABLE 1-8 PART PRICE_UPDATES SALES REP

Explanation / Answer

List the total number of parts ordered on each day. Rank your results in ascending order on order date.

1. select sum(a.number_ordered) as totalPartsOrdered, b.order_date from order_line a, orders b where b.order_number=a.order_number group by b.order_date order by b.order_date

List the full name and mailing address of customers who placed an order on 04-AUG-2013. If same customer has placed more than one order on this day, only show his/her information once.

2. select concat(CFIRST, CLAST) as full_name , concat(street , concat(city ,concat(state, zipcode))) as mailing_address from customer where c_number in (select distinct c_number from orders where trunc(order_date)=’04-AUG-2013’)

List the order date, order number, total quoted price for each order placed between 03-AUG2013 and 06-AUG-2013.

3. select b.order_date, b.order_number, sum(a.quoted_price) from order_line a, orders b where b.order_number=a.order_number and trunc(order_date)>’02-AUG-2013’ and trunc(order_date)<’07-AUG-2013’ group by order_number

List the average commission rate (rename to AVG_RATE) and the highest total commission (rename to MAX_COMMISSION) of sales representatives who sold SG class items.

4. select avg(sr.commission_rate) as AVG_RATE, max(sr.total_commission) as MAX_COMMISSION from customer c, orders o, order_line as ol, part as p, sales_rep as sr where c.slsrep_number=sr.slsrep_number and c.c_number=o.c_number and ol.order_number=o.order_number and ol.part_number=p.part_number and p.item_class=‘SG’

List the warehouse number and the total number of orders from each warehouse.

5. select p.warehouse_number, sum(number_ordered) from orders o, order_line as ol, part as p where ol.order_number=o.order_number and ol.part_number=p.part_number group by p.warehouse_number

List the full name of the sales representatives, order number, and total quoted price for each order (rename to TQP) handled by each sales representative.

6. select concat(sr.srfirst , sr.srlast) as fullname, o.order_number, sum(quoted_price) as TQP from customer c, orders o, order_line as ol, sales_rep as sr where c.slsrep_number=sr.slsrep_number and c.c_number=o.c_number and ol.order_number=o.order_number group by sr.slsrep_number

List the part number and part description of parts with units on hand higher than the average units on hand across all parts.

7. select p.part_number, p.part_description from parts as p where p.units_on_hand> (select avg(p1.units_on_hand) from parts p1)

List the full name and credit limit of customer who bought a Gas Grill.

8. select concat(c.CFIRST, c.CLAST) as full_name, c.credit_limit from customer1 c, orders o, order_line as ol, part as p where c.c_number=o.c_number and ol.order_number=o.order_number and ol.part_number=p.part_number and p.part_description =‘Gas Grill’

List the warehouse number and total dollar amount of all items sold from that warehouse. Rename the calculated column TOTAL_VALUE.

10. select p.warehouse_number, sum(ol.quoted_price * ol.number_ordered) as TOTAL_VALUE from order_line as ol, part as p where ol.part_number=p.part_number group by p.warehouse_number

List the part description of the part with the most units on hand.

11. select part_description from part where units_on_hand = ( select max(units_on_hand) from part group by part_number)

List the part description of the part that was sold the most (in terms of total number ordered).

12. select p.part_description from order_line as ol, part as p where ol.part_number=p.part_number where number_ordered=max(sum(number_ordered)) group by p.part_number

List the full name and number of different parts for each order each customer has placed. Rename the calculated column as TOTAL_PARTS.

13. select p.part_description, sum(ol.number_ordered) from customer c, orders o, order_line as ol, part as p where c.c_number=o.c_number and ol.order_number=o.order_number and ol.part_number=p.part_number group by part_number, c_number, order_number

List the order date of an order containing a part description with letter D (or d) in it.

14. select order_date from orders o, order_line as ol, part as p where ol.order_number=o.order_number and ol.part_number=p.part_number and upper(p.part_description) like ‘%D%’

List the customer name of those who purchased products with a unit price of more than $150.

15. select concat(c.CFIRST , c.CLAST) as full_name, c.credit_limit from customer1 c, orders o, order_line ol, part p where c.c_number=o.c_number and ol.order_number=o.order_number and ol.part_number=p.part_number and p.unit_price>150;

List sales representative number and the number of customers handled by each sales representative who got paid at most as the average total commission.

16. select concat(sr.srfirst, sr.srlast) as fullname, count(c.c_number) as no_customers from customer1 c, sales_rep sr where c.slsrep_number=sr.slsrep_number and total_commission < avg(total_commission) group by sr.slsrep_number