1. SQL Chip
When analyzing holiday data, raw transaction logs are often too granular to be useful on their own. To turn thousands of individual purchases into a clear picture of performance, we use Aggregation. By combining the SUM() function with the GROUP BY clause, you can collapse thousands of rows into a single, digestible metric—like "Total Revenue per Category." This allows you to identify which product categories are driving your holiday success without getting lost in the noise of individual receipts.
2. SQL Chunk
Here is a standard query you might run to analyze December performance. We are joining a transactions table with a products table to see the names of what we are selling, filtering specifically for December activity, and summing up the total sales.
SELECT
p.category_name,
COUNT(t.transaction_id) AS total_items_sold,
SUM(t.sales_amount) AS total_revenue
FROM transactions AS t
JOIN products AS p
ON t.product_id = p.product_id
WHERE t.transaction_date >= '2024-12-01'
AND t.transaction_date <= '2024-12-31'
GROUP BY p.category_name
ORDER BY total_revenue DESC;
3. SQL Challenge
Now, let's level up. A business owner doesn't just want to know how much they made this December; they need to know if they are growing compared to last December.
This is called a Year-Over-Year (YoY) analysis. Instead of just filtering for one month, we will look at two years of data. We can use "conditional aggregation" (putting a CASE statement inside a SUM) to create separate columns for this year's sales and last year's sales in a single view.
SELECT
p.category_name,
-- Dec 2023 Revenue: Includes everything from Dec 1 up to (but not including) Jan 1
SUM(CASE
WHEN t.transaction_date >= '2023-12-01' AND t.transaction_date < '2024-01-01'
THEN t.sales_amount
ELSE 0
END) AS revenue_dec_2023,
-- Dec 2024 Revenue: Includes everything from Dec 1 up to (but not including) Jan 1
SUM(CASE
WHEN t.transaction_date >= '2024-12-01' AND t.transaction_date < '2025-01-01'
THEN t.sales_amount
ELSE 0
END) AS revenue_dec_2024
FROM transactions AS t
JOIN products AS p
ON t.product_id = p.product_id
WHERE t.transaction_date >= '2023-12-01'
GROUP BY p.category_name
ORDER BY revenue_dec_2024 DESC;4. SQL Mistake
The Mistake: Trying to filter aggregate results using WHERE.
It is incredibly common to try to filter for "High Revenue" categories by putting the condition in the WHERE clause. However, WHERE filters rows before they are grouped and summed. The database doesn't know the "Total Revenue" yet when it is processing the WHERE clause.
Incorrect:
SELECT category_name, SUM(sales_amount)
FROM transactions
WHERE SUM(sales_amount) > 10000 -- This causes an error!
GROUP BY category_name;
Correct: Use HAVING. The HAVING clause was designed specifically to filter data after the aggregation has happened.
SELECT category_name, SUM(sales_amount)
FROM transactions
GROUP BY category_name
HAVING SUM(sales_amount) > 10000;
5. SQL in Practice
Let's look at an E-Commerce scenario. Imagine you are working for a large online retailer. The marketing team wants to identify their "Holiday Heroes"—specific products that not only sold well in December but also maintained a high average order value. They only want to see products that generated over $50,000 in revenue to ensure they are focusing on high-impact items for restocking.
SELECT
p.product_name,
p.category_name,
COUNT(t.transaction_id) AS units_sold,
AVG(t.sales_amount) AS average_sale_price,
SUM(t.sales_amount) AS total_holiday_revenue
FROM transactions AS t
JOIN products AS p
ON t.product_id = p.product_id
WHERE t.transaction_date >= '2024-12-01' AND t.transaction_date < '2025-01-01'
GROUP BY p.product_name, p.category_name
HAVING SUM(t.sales_amount) > 50000
ORDER BY total_holiday_revenue DESC
LIMIT 10;
6. SQL Resource
Why this helps: When you are analyzing holiday trends, date formats can be the biggest stumbling block. One database might look for YYYY-MM-DD while another expects MM/DD/YYYY. This free guide is an excellent cheat sheet that breaks down exactly how to handle date formats and data types across different SQL systems (like MySQL, SQL Server, and MS Access). It is perfect for troubleshooting those "Year-Over-Year" queries when the dates just won't line up.

