Problems / Pivot Sales Data / Editorial
This is the classic pivot pattern — converting row values into column headers.
Since SQL has no universal PIVOT keyword, we use conditional aggregation:
product_name
SUM(CASE WHEN quarter = 'Q1' THEN revenue END)
NULL
The number of output columns must be known at query-write time. This technique generalizes to any row-to-column transformation where the set of pivot values is fixed.
Solve Pivot Sales Data yourself →