iCloud Storage Plan Segments
How many customers fall into each iCloud storage tier, and what is the average storage in each group?
- Aggregation
- CASE expressions
- Numeric functions
- Sorting
Challenge brief
Understand the request
iCloud Business Team is reviewing the distribution of storage plan tiers to inform pricing strategy.
Segment customers by iCloud storage tier using CASE WHEN and show count and average per tier.
Return
- storage_tier
- customer_count
- avg_storage_gb (rounded)
Constraints
- Enterprise includes 2,000GB or more; Standard includes 200–1,999GB; Basic is below 200GB
- Show the highest average storage first
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
customers
customer_idINTEGERicloud_storage_gbINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
All data is in customers. Use CASE WHEN on the icloud_storage_gb column to assign each customer to a tier. Then GROUP BY that expression and COUNT.
Hint 2
CASE WHEN icloud_storage_gb >= 2000 THEN 'Enterprise (2TB+)' WHEN icloud_storage_gb >= 200 THEN 'Standard (200GB)' ELSE 'Basic (50GB)' END AS storage_tier. GROUP BY storage_tier. COUNT(*), ROUND(AVG(...)).
Hint 3
Build question 13 from its business grain: identify the driving rows, add only valid relationships, then apply the required filtering, aggregation, and deterministic ordering.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT CASE WHEN icloud_storage_gb >= 2000 THEN 'Enterprise (2TB+)' WHEN icloud_storage_gb >= 200 THEN 'Standard (200GB)' ELSE 'Basic (50GB)' END AS storage_tier, COUNT(*) AS customer_count, ROUND(AVG(icloud_storage_gb), 0) AS avg_storage_gb FROM customers GROUP BY storage_tier ORDER BY avg_storage_gb DESCWhy this works
CASE WHEN evaluates top-down: >= 2000 is checked first (catches the 2TB customer), then >= 200 (catches the 200GB customers), then ELSE catches everyone else. GROUP BY on a CASE expression groups by the label it produces.
Success check
3 tiers — Enterprise (1 customer: Carol White at 2TB), Standard (3 customers at 200GB), Basic (2 customers at 50GB)
Expected result
Use this output to verify values, aliases, ordering, and row count.
| storage_tier | customer_count | avg_storage_gb |
|---|---|---|
| Enterprise (2TB+) | 1 | 2000 |
| Standard (200GB) | 3 | 200 |
| Basic (50GB) | 2 | 50 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Microsoft
Independent Microsoft-style cloud, productivity, subscription, usage, support, and customer analytics 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.