SQL Programming
SQL Programming
May 13, 2025 at 05:32 PM
Let's now move to the next topic in the SQL Learning Series *Aggregations & Grouping!* Aggregate functions can crunch numbers across multiple rows to give a single output (or per group. Let's discussion widely used aggregate functions: *1. COUNT()* Counts the number of non-null rows. SELECT COUNT(*) FROM orders; -- Total number of rows (orders) *2. SUM()* Adds up values in a column. SELECT SUM(amount) FROM orders; -- Total revenue *3. AVG()* Calculates the average. SELECT AVG(rating) FROM reviews; -- Average product rating *4. MIN() / MAX()* Finds smallest or largest value. SELECT MIN(price), MAX(price) FROM products; -- Lowest and highest priced items *Real-Life Example:* SELECT COUNT(*) AS total_orders, SUM(amount) AS total_revenue, AVG(amount) AS avg_order_value FROM orders; *What it does:* - COUNT(*) counts all the orders placed. - SUM(amount) adds up all the money earned — total revenue. - AVG(amount) calculates the average value of an order. This query is often used by analysts or business teams to quickly get a performance snapshot — like a mini dashboard in a single SQL statement. *React with ❤️ if you're ready for the next quiz.* 📝 SQL Learning Series: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v/1075
❤️ 👍 🇵🇸 🇮🇳 😂 🙏 🇮🇱 🍗 113

Comments