Revenue by Product
How much total subscription revenue has each Microsoft product generated?
- Joins
- Aggregation
- NULL handling
- Sorting
Challenge brief
Understand the request
Finance Team is preparing the quarterly P&L and needs total subscription revenue broken down by product line.
Sum subscription prices per product name by joining subscriptions to products.
Return
- product_name
- revenue
Constraints
- Include every catalog product, even when it has no subscriptions
- Treat missing subscription revenue as zero
- Show the highest revenue first
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
subscriptions
subscription_idINTEGERuser_idINTEGERproduct_idINTEGERstart_dateDATEend_dateDATEpriceINTEGER
products
product_idINTEGERproduct_nameTEXTcategoryTEXT
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Revenue data (price) is in subscriptions. Product names are in products. JOIN on product_id, GROUP BY product, SUM the price.
Hint 2
INNER JOIN subscriptions to products on product_id. GROUP BY p.product_name. SUM(s.price) AS revenue.
Hint 3
Build question 10 from the required result grain: choose the driving table, add only the joins and filters needed for that grain, then apply aggregation and deterministic ordering.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT p.product_name, COALESCE(SUM(s.price), 0) AS revenue FROM products p LEFT JOIN subscriptions s ON p.product_id = s.product_id GROUP BY p.product_id, p.product_name ORDER BY revenue DESC, p.product_name;Why this works
Drive from the catalog so products without subscriptions remain visible, aggregate subscription prices once, and convert only the missing revenue total to zero.
Success check
3 products — Azure leads ($1200), Office ($600), Teams ($240). Dynamics has no subscriptions.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| product_name | revenue |
|---|---|
| Azure | 1500 |
| Microsoft Office | 600 |
| Teams | 240 |
| Dynamics | 0 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Apple
Independent Apple-style product, retail, services, support, workforce, and device-usage SQL practice.
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Return to the complete interview preparation experience.