3 SQL Statements. Here are the relational database tables PARTS(PNO, PNAME, QOH,
ID: 3746151 • Letter: 3
Question
3 SQL Statements. Here are the relational database tables PARTS(PNO, PNAME, QOH, PRICE, OLEVEL) CUSTOMERS(CNO, CNAME, STREET, ZIP, PHONE) EMPLOYEES(ENO, ENAME, ZIP, HDATE) ZIPCODES(ZIP, CITY) ORDERS(ONO, CNO, ENO, RECIEVED, SHIPPED) ODETAILS(ONO, PNO, QTY) 1.Retrieve a list of part numbers, part name, and total quantity ordered for that part. Produce a listing sorted in decreasing order of the total quantity ordered. 2.Retrieve the average waiting time(number of days) for all orders. The waiting time is defined as the difference between shipping date and order date received date rounded up the the nearest day. 3.For each employee, retrieve his number, name, and total sales in a given year, say 2005.
Explanation / Answer
Answer)
Q1)
select PARTS.PNO, PARTS.PNAME, sum(ODETAILS.QTY) from PARTS inner join ODETAILS on PARTS.PNO = ODETAILS.PNO
group by PARTS.PNO order by sum(ODETAILS.QTY) desc;
Q2)
select avg(DATEDIFF(day, SHIPPED, RECIEVED)) as AverageWaitTime from ORDERS;
Using DATEDIFF function to calculate difference in days.
Q3)
select EMPLOYEES.ENO, EMPLOYEES.ENAME, count(ORDERS.ONO) from EMPLOYEES inner join ORDERS on EMPLOYEES.ENO = ORDERS.ENO group by EMPLOYEES.ENO having YEAR(ORDERS.RECIEVED)=2005;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.