Lessons › SQL › Deep Dive: Data Cleaning
SQL lesson
Data profiling with MIN, MAX, COUNT DISTINCT, and AVG
Data profiling means running a quick snapshot of a column's extremes, average, and variety before touching anything - finding the lowest value, highest value, mean, and count of unique entries in one pass.
Try this lesson free →Example
Profiling Retail Product Data Before Cleaning
SELECT MIN(price) AS min_price,
MAX(price) AS max_price,
AVG(price) AS avg_price,
COUNT(DISTINCT category) AS distinct_categories
FROM products| min_price | max_price | avg_price | distinct_categories |
|---|---|---|---|
| 12.75 | 9999.0 | 2075.45 | 4 |
Step by step
- Run the query without COUNT so you can see what the unfiltered values look like.
SELECT MIN(price) AS min_price, MAX(price) AS max_price, AVG(price) AS avg_price, DISTINCT FROM products; - COUNT tells you how many rows match - perfect for sizing a table.
SELECT MIN(price) AS min_price, MAX(price) AS max_price, AVG(price) AS avg_price, COUNT(DISTINCT category) FROM products; - AS gives the COUNT result a friendly column name so the output reads cleanly.
SELECT MIN(price) AS min_price, MAX(price) AS max_price, AVG(price) AS avg_price, COUNT(DISTINCT category) AS distinct_categories FROM products;
Practice
1. Using orders, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM orders2. Using products, write a query to find the average of the price column.
SELECT AVG(price) FROM products3. Using customers, write a query to find the average of the phone column.
SELECT AVG(phone) FROM customers4. Using store_sales, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM store_sales5. Using returns, write a query to find the average of the refund_amount column.
SELECT AVG(refund_amount) FROM returnsLearn 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 →