DE Interview: Pivot / Unpivot
complete interview-ready guide for š¹ PATTERN 13: Pivot / Unpivot šÆ Core skill: Transform rows ↔ columns Designed for 6–8 years experience , with real interview questions + solutions in: ✅ SQL Basic ✅ SQL Advanced ✅ PySpark Basic ✅ PySpark Advanced / Optimized š¹ Assumed Interview Dataset sales order_id | order_date | region | product | metric | value ------------------------------------------------------------ 1 | 2024-01-01 | East | Laptop | revenue | 1000 2 | 2024-01-01 | East | Laptop | quantity | 2 3 | 2024-01-01 | West | Mobile | revenue | 800 1️⃣ Pivot Product Rows into Columns (Total Revenue) š¢ SQL – Basic (CASE WHEN) SELECT region, SUM ( CASE WHEN product = 'Laptop' THEN value END ) AS laptop_revenue, SUM ( CASE WHEN product = 'Mobile' THEN value END ) AS mobile_revenue FROM sales WHERE metric = 'revenue' GROUP BY region; š Most common interview pivot...