The Product's Price for Each Store SQL problem asks you to pivot a Products table (product_id, store, price) into a wide format with one column per store. This easy SQL problem tests conditional aggregation (CASE WHEN) for pivot operations. The database interview pattern is demonstrated.
Amazon and McAfee ask this to test SQL pivoting — converting rows to columns. This is a fundamental data transformation skill in analytics and reporting.
Conditional aggregation (pivot). SELECT product_id, MAX(CASE WHEN store='store1' THEN price END) AS store1, MAX(CASE WHEN store='store2' THEN price END) AS store2, MAX(CASE WHEN store='store3' THEN price END) AS store3 FROM Products GROUP BY product_id.
Products: (1,store1,95),(1,store2,70),(1,store3,105),(2,store1,70),(2,store3,80). Pivoted: prod1→(95,70,105), prod2→(70,NULL,80). Result: [(1,95,70,105),(2,70,NULL,80)].
SQL pivoting uses CASE WHEN inside aggregate functions. The pattern: MAX(CASE WHEN category='X' THEN value END) AS X. Always GROUP BY the row identifier. For dynamic pivots (unknown number of stores), use dynamic SQL or Python/pandas. Practice pivoting for: "revenue by month," "scores by subject," "count by category." Conditional aggregation is the universal SQL pivot technique.