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