SQL data engineering interview problem. Difficulty: intermediate. Pattern: Pivot. About 12 minutes. Part of the Pro drill bank.
From sales(product_id, month, revenue), pivot months into columns. Return product_id, jan_revenue, feb_revenue, mar_revenue. Month labels in the seed are 'Jan', 'Feb', 'Mar'. Order by product_id.
Input: sales product_id | month | revenue P1 | Jan | 100 P1 | Feb | 120 P1 | Mar | 90 Output: product_id | jan_revenue | feb_revenue | mar_revenue P1 | 100 | 120 | 90 Why this passes: Conditional aggregation turns month rows into columns.
Topics: lakebench, sql, pivot, case.
More SQL interview questions · All interview problems · Learn data engineering
Interview-style drill: Pivot Jan/Feb/Mar revenue into columns.
From `sales(product_id, month, revenue)`, pivot months into columns. Return `product_id`, `jan_revenue`, `feb_revenue`, `mar_revenue`. Month labels in the seed are 'Jan', 'Feb', 'Mar'. Order by `product_id`.