BBampaa

Lessons › SQL › Chapter 3: Summarising

SQL lesson

AVG()

AVG adds the numbers in a column and divides by how many there are. Empty cells (NULL) are skipped, so they don't pull the average down.

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

Example

The average

SELECT AVG(revenue) AS avg_revenue
FROM orders

Result:

avg_revenue
135.1

Step by step

  1. Adds the values and divides by how many there are.
    SELECT AVG(revenue) AS avg_revenue FROM orders
  2. The whole column becomes one number.
    SELECT AVG(revenue) AS avg_revenue FROM orders
  3. Empty cells aren't counted, so they don't pull the average down.
    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, show the average salary and the total salary, as two columns.
SELECT AVG(salary), SUM(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