5.4

Improving the GROUP BY Query

Improving the GROUP BY Query

Code Sample:

USE bike;
SELECT category_name, 
    CONCAT('$', ROUND(AVG(list_price),2)) AS 'Average List Price'
FROM product p
    JOIN category c
    ON p.category_id = c.category_id
GROUP BY category_name
ORDER BY category_name;

Output:

ag_03.png

USE bike:

SELECT category_name,

     CONCAT('$', ROUND(AVG(list_price),2)) AS 'Average List Price'

FROM product p

     JOIN category c

    ON p.category_id = c.category_id

GROUP BY category_name

ORDER BY category_name;