BBampaa

Lessons › SQL › Chapter 3: Summarising

SQL lesson

AVG()

AVG() adds up all the values in a column and divides by how many there are, giving you a single number that represents the middle ground.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Finding Typical Retail Values with AVG()

SELECT AVG(revenue) AS avg_revenue
FROM orders

Result:

avg_revenue
135.1

Step by step

  1. Run the query without AVG so you can see what the unfiltered values look like.
    SELECT revenue
    FROM orders;
  2. AVG returns the mean of the values in a column.
    SELECT AVG(revenue)
    FROM orders;
  3. AS gives the AVG result a friendly column name so the output reads cleanly.
    SELECT AVG(revenue) AS avg_revenue
    FROM orders;

Practice

Try each one in your head first, then open the answer.

1. Using orders, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM orders
2. Using store_sales, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM store_sales
3. Using products, write a query to find the average of the price column.
SELECT AVG(price) FROM products
4. Using reviews, write a query to find the average of the rating column.
SELECT AVG(rating) FROM reviews
5. Using employees, write a query to find the average of the salary column.
SELECT AVG(salary) FROM employees

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed