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 →Example
Finding Typical Retail Values with AVG()
SELECT AVG(revenue) AS avg_revenue
FROM orders| avg_revenue |
|---|
| 135.1 |
Step by step
- Run the query without AVG so you can see what the unfiltered values look like.
SELECT revenue FROM orders; - AVG returns the mean of the values in a column.
SELECT AVG(revenue) FROM orders; - AS gives the AVG result a friendly column name so the output reads cleanly.
SELECT AVG(revenue) AS avg_revenue FROM orders;
Practice
1. Using orders, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM orders2. Using store_sales, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM store_sales3. Using products, write a query to find the average of the price column.
SELECT AVG(price) FROM products4. Using reviews, write a query to find the average of the rating column.
SELECT AVG(rating) FROM reviews5. Using employees, write a query to find the average of the salary column.
SELECT AVG(salary) FROM employeesLearn 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 →