Reshaping
SQL Reshaping Interview Questions
Reshaping turns rows into columns, or columns into rows — one row per month becoming one column per month, or the other way round. The shape a database stores data in is rarely the shape somebody wants to read.
What reshaping questions ask you to do
Across the questions here, these are the shapes that come up:
- Turn the values in one column into several columns
- Turn several columns back into rows
- Build a grid of counts or totals
- Flatten a nested or repeated structure into rows
Common mistakes with reshaping
Turning rows into columns in SQL needs one CASE per output column, which means the columns have to be known before the query is written — SQL cannot discover its own column names. In pandas the two tools differ too: pivot refuses duplicate pairs while pivot_table quietly averages them, and that difference is easy to miss.
Questions to practice
- Cancellation split by restaurantSQL
Swiggymedium - Damage share of refundsSQL
Flipkartmedium - Money moved by payment typeSQL
PhonePemedium - Pins by categoryPandas
Pinterestmedium - Priority mix per projectSQL
Atlassianmedium - Reactions by post typePandas
Metamedium - Returns by reasonSQLPremium
Flipkartmedium - Revenue by plan and monthPandas
Shopifymedium - Severity mix per serviceSQL
Datadogmedium - Spend by channelSQLPremium
Nykaamedium - Stage times per packageSQL
Amazonmedium - Cost per order gridPandasPremium
Nykaahard - Holdings in long formatPandasPremium
Robinhoodhard - Hours lost by dayPandas
PagerDutyhard - Net position gridPandasPremium
Zerodhahard
Questions last reviewed 19 October 2026.