This guide is specifically for PostgreSQL syntax.
Advanced-level SQL GROUP BY practice exercises with solutions.
Exercise 1
Question: Find total revenue by product category and month.
SELECT product_category, DATE_TRUNC('month', order_date) AS month, SUM(amount) AS total_revenue FROM orders GROUP BY product_category, DATE_TRUNC('month', order_date) ORDER BY month, total_revenue DESC;
Group by multiple columns for multi-dimensional analysis. DATE_TRUNC normalizes dates to month boundaries.
PostgreSQL-Specific Notes
This page covers PostgreSQL syntax. Other databases may have different syntax for similar operations.