Using COUNT, SUM, AVG, MIN, MAX in PostgreSQL
📖 Scenario: You are working with a small store's sales database. The store wants to analyze its sales data to understand how many products were sold, the total sales amount, average price, and the cheapest and most expensive products sold.
🎯 Goal: Build SQL queries step-by-step to use the aggregate functions COUNT, SUM, AVG, MIN, and MAX on the sales data.
📋 What You'll Learn
Create a table called
sales with columns product (text) and price (numeric).Insert the exact sales data given into the
sales table.Write a query to count the number of sales using
COUNT(*).Write a query to calculate the total sales amount using
SUM(price).Write a query to find the average price of sold products using
AVG(price).Write a query to find the minimum and maximum price using
MIN(price) and MAX(price).💡 Why This Matters
🌍 Real World
Stores and businesses use these aggregate functions to analyze sales, inventory, and customer data to make informed decisions.
💼 Career
Knowing how to use COUNT, SUM, AVG, MIN, and MAX is essential for data analysts, database administrators, and backend developers working with databases.
Progress0 / 4 steps