# @aartii.py on Instagram

- **Type:** Video
- **Original URL:** https://www.instagram.com/p/DSfDkO6D9Pj
- **Gondola URL:** https://gondola.cc/posts/59916251-aartiipy-instagram
- **Thumbnail:** https://img.gondola.cc/tr:w-,h-,fo-auto/postThumbnails/72fe43b196.jpg
- **Posted:** 2025-12-20T12:32:28.000+00:00
- **Account Owner:** Aarti Sinha (@aartii.py) — https://gondola.cc/aartii.py

## Caption

Day 2/7 - SQL Challenge 🎯
TODAY'S QUESTION:
Calculate total sales for each month in 2024.
TABLE:
Orders (id, customer_id, amount, order_date)
THE SOLUTION:
SELECT 
  DATE_FORMAT(order_date, '%Y-%m') as month,
 SUM(amount) as total_sales
FROM Orders
WHERE YEAR(order_date) = 2024
GROUP BY month
ORDER BY month;
BREAKDOWN:
DATE_FORMAT(order_date, '%Y-%m') - Extracts year-month (2024-01, 2024-02, etc.)
WHERE YEAR(order_date) = 2024 - Filters only 2024 data
GROUP BY month - Groups all sales by month
SUM(amount) - Adds up all sales per month
ORDER BY month - Shows chronologically
COMMON MISTAKES:
❌ Not formatting date (GROUP BY raw dates)
❌ Forgetting WHERE clause (includes all years)
❌ Wrong date function syntax
ALTERNATIVE (PostgreSQL):
SELECT 
  TO_CHAR(order_date, 'YYYY-MM') as month,
 SUM(amount) as total_sales
FROM Orders
WHERE EXTRACT(YEAR FROM order_date) = 2024
GROUP BY month
ORDER BY month;
WHY THIS IS ASKED:
Tests your understanding of:
Date functions (every SQL dialect has different syntax)
GROUP BY with aggregations
Filtering before grouping
INTERVIEW TIP:
Always ask which SQL dialect (MySQL, PostgreSQL, SQL Server) - date functions vary!
Day 2/7 complete ✅
#SQLChallenge #Day2 #Aggregations #DataScience #SQL DateFunctions

## Stats

- **Views:** 2,174
- **Likes:** 166
- **Shares:** 0
- **Comments:** 15

## Tags

sqlchallenge, sql, day2, datascience, aggregations

---
Copyright (c) Gondola