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

***The answer must be typed! Not written! Given the following view: PURCHASE_INF

ID: 3728647 • Letter: #

Question

***The answer must be typed! Not written! Given the following view: PURCHASE_INFO Write a MySQL query to find the average of unit prices of the products purchased by each customer (each customer has a unique CUS_CODE). Return the results sorted in ascending by CUS_CODE, as follows in Table-5. . View: PURCHASE INFO VIEW: PURCHASE INFO | CUS CODE | CUS FNAME | CUS_LNAME I UNIT PRICE QUANTITY| DESCRIPTION 10014 | Myron Orland 14.99 9.95 4.99 38.95 39.95 I 14.99 I 4.99 1 | 7.25-in. pwr. saw blade 1 | Claw hammer 2 I Rat-tail file, 1/8-in. fine 1 | B&D; cordless drill, 1/2-in 1 | Hrd. cloth, 1/4-in., 2x5e 5 | 7.25-in. pwr. saw blade 3 | Rat-tail file, 1/8-in. fine 2 Claw hammer 10014 | Myron 10011 | Leona 10012 | Kathy Orlando Dunne 10012 | Kathy Smith 10012 | Kathy Smith I 10011 | Leona Dunne 10011 | Leona 10018 | Anne 10014 | Myron 10014 | Myron 10014 | Myron Dunne arriss Orlando 12 PVC pipe, 3.5-in., 8-ft 5.87 6.99 31.25-in. metal screw, 25 1 B&D; jigsaw, 12-in. blade 1 | Claw hammer 1 Hicut chain saw, 16 in 2 I 7.25-in. pwr. saw blade 1 | Rat-tail file, 1/8-in. fine 5 | PVC pipe, 3.5-in., 8-ft 3 | Steel matting, 4'x8'x1/6", .5" mesh 1 Claw hammer Orlando 109.92 I Orlando 9.95 10014 | Myron Orlando 256.99 | I 10015 | Amy | O'Briarn 14.99 10015 | Amy 10011 | Leona 10011 | Leona 10011 | Leona O'Brian Dunne Dunne 119.95 | Dunne 9.95 18 rows in set CUS CODE 1 CUS FNAME CUS LNAME Avg price (S) Table-5: 10011 Leona 10012 Kathy 10014 Myron 10015 Amy 10018 Anne Dunne Smith Orlando O'Brian Farriss 25.95 31.30 68.13 9.99 5.87

Explanation / Answer

Answer is as follows:

SELECT CUS_CODE, CUS_FNAME, CUS_LNAME, AVG(UNIT_PRICE) as Avg_Price FROM PURCHASE_INFO GROUP BY CUS_CODE ORDER BY CUS_CODE;

Select statement is used to fetch the cus_code, cus_fname, cus_lname and average of unit prices.

avg function is used to calculate the average of unit prices.

Group by clause is used to define each record by cus_code so that different average is found for each customer.

Order by clasue is used to order the records in ascending order.

if there is any query please ask in comments....