Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Unpivot wide sales to rows

SQL data engineering interview problem. Difficulty: intermediate. Pattern: Pivot. About 12 minutes. Part of the Pro drill bank.

From sales_wide(product_id, jan, feb, mar), unpivot to: product_id, month ('Jan'/'Feb'/'Mar'), revenue. Order by product_id, then month in calendar order (Jan, Feb, Mar).

Constraints

  • month must be exactly 'Jan', 'Feb', or 'Mar'.

Examples

Input: sales_wide product_id | jan | feb | mar P1 | 100 | 120 | 90 Output: product_id | month | revenue P1 | Jan | 100 P1 | Feb | 120 P1 | Mar | 90 Why this passes: Each wide column becomes a row with a month label.

Topics: lakebench, sql, unpivot.

More SQL interview questions · All interview problems · Learn data engineering

intermediate

Unpivot wide sales to rows

Interview-style drill: Unpivot jan/feb/mar columns into month/revenue rows.

From `sales_wide(product_id, jan, feb, mar)`, unpivot to: `product_id`, `month` ('Jan'/'Feb'/'Mar'), `revenue`. Order by `product_id`, then month in calendar order (Jan, Feb, Mar).