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

Write and SQL statement for these two queries. 1. For each part in the INVENTORY

ID: 3870188 • Letter: W

Question

Write and SQL statement for these two queries.

1. For each part in the INVENTORYPART table, display its description, part number, and the average quantity sold on any order placed for that part. Round the average to the closest whole number, then sort the results by part description.

2. For each year in which part CF-004 was ordered at least once, display its description, part number, year, and the average quantity sold on any order placed for CF-004 during a given year. Round the average to 1 decimal place, then sort the results first by part description, then year.

COMPANY NAME: vachr (40) CONTACINAMEacha220 PARTNUMBER:h10FK REQUIREDDATE dane REVISIONLEVELarcha210) PARTNUMBER varchar2oFK SHPSTATE:2 MACHINEID: ahar FK PROCESSID: varcharFK SETUPALLOWEDaha2) EMPLOYEEIDha0FK

Explanation / Answer

Hi,
1. Here we have to deal with 2 tables INVENTORYPART and CUSTORDERLINE, to get quantity of that part
select round(avg(ORDERQUANTITY)),a.PARTDESCRIPTION,a.PARTNUMBER from INVENTORYPART a,CUSTORDERLINE b where a.PARTNUMBER=b.PARTNUMBER group by a.PARTNUMBER order by a.PARTDESCRIPTION;

here first we are joining based on part number and then taking the average of the order quantity, round() rounds the average to closest integer
2.For this we need CUSTORDER table as it has date column.
select round(avg(ORDERQUANTITY),1),a.PARTDESCRIPTION,a.PARTNUMBER from INVENTORYPART a,CUSTORDERLINE b, CUSTORDER c where a.PARTNUMBER=b.PARTNUMBER and b.ORDERID=c.ORDERID and a.PARTNUMBER='CF-004' and b.QUANTITY>=1 group by c.ORDERDATE order by a.PARTDESCRIPTION,c.ORDERDATE;
here first we join 3 tables like INVENTORYPART and CUSTORDERLINE on part number and then CUSTORDERLINE and CUSTORDER on orderid then we put the partnumber and quantity condition and then group by the date so find date aggregated results. round(x,1) rounds the results to 1 decimal places
Thumbs up if this was helpful, otherwise let me know in comments.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote