BBampaa

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 →
About 5–10 minutes · no sign-up needed

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

Result:

min_pricemax_priceavg_pricedistinct_categories
12.759999.02075.454

Step by step

  1. 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;
  2. 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;
  3. 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

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 products, write a query to find the average of the price column.
SELECT AVG(price) FROM products
3. Using customers, write a query to find the average of the phone column.
SELECT AVG(phone) FROM customers
4. Using store_sales, write a query to find the average of the revenue column.
SELECT AVG(revenue) FROM store_sales
5. Using returns, write a query to find the average of the refund_amount column.
SELECT AVG(refund_amount) FROM returns

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