Paths Subjects Questions Quizzes Pricing Search
Advanced Open Pro

Pivoting Monthly Revenue by Category Into Columns

Given a normalized fact table:

monthly_category_revenue
month_num | category    | revenue
----------+-------------+--------
1         | Electronics | 50000
1         | Apparel     | 30000
2         | Electronics | 62000
2         | Apparel     | 28000
2         | Home        | 15000
3         | Electronics | 58000
3         | Apparel     | 33000

Produce a report with one row per month and one column per category (electronics_revenue, apparel_revenue, home_revenue, ...), so it can be dropped straight into a spreadsheet-style view.

  1. Write the pivot assuming the category list is known and fixed ahead of time.
  2. Explain, in words (no need for full working SQL), what breaks about this approach the moment a new category can appear in the data at any time, and what you'd actually do about it in a production pipeline rather than at query time.

Share this question

← Back to Case Study: The SQL Interview Gauntlet practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.