Pivoting Monthly Revenue Rows into Columns with Conditional Aggregation
CREATE TABLE dept_income (
dept_id INT,
mon VARCHAR(3),
income INT
);
INSERT INTO dept_income VALUES
(1,'Jan',8000),(1,'Feb',7000),(1,'Mar',6000),
(2,'Jan',9000),(2,'Feb',8000),(2,'Mar',7000);
The goal is to transform the above row-oriented data into a single row per department with twelve monthly columns.
Why GROUP BY ...
Posted on Fri, 25 Sep 2026 16:10:25 +0000 by ipwnzphp