5.3

# Simple GROUP BY Query

Code Example:

USE bike;SELECT category_id, AVG(list_price)FROM productGROUP BY category_id

Results:

USE bike:

• Set the bike database to be the default

SELECT category_id, AVG(list_price):

• Select the category_id from the base table
• Calculate the Average of the list price for all rows in the table

FROM product:

• Product is the base table from which data will be returned

GROUP BY category_id:

• Instead of returning a single value that is the average of all list_price items in the product table, return an average list_price for each category
• Without the GROUP BY clause, we see from our first example only a single row is returned with an average list_price of 1520.591402.
• With the GROUP BY clause, we return an average for each category_id.

CC BY-NC-ND International 4.0: This work is released under a CC BY-NC-ND International 4.0 license, which means that you are free to do with it as you please as long as you (1) properly attribute it, (2) do not use it for commercial gain, and (3) do not create derivative works.

### End-of-Chapter Survey

: How would you rate the overall quality of this chapter?
1. Very Low Quality
2. Low Quality
3. Moderate Quality
4. High Quality
5. Very High Quality
Comments will be automatically submitted when you navigate away from the page.