Table Schema
Inspect
Table
| Column | Type |
|---|---|
| user_id | integer |
| plan_type | varchar |
| storage_used_gb | decimal |
Calculate total storage used per subscription plan.
Table Schema
| Column | Type |
|---|---|
| user_id | integer |
| plan_type | varchar |
| storage_used_gb | decimal |
Sample Data
| user_id | plan_type | storage_used_gb |
|---|---|---|
| 101 | Free | 5 |
| 102 | Premium | 50 |
| 103 | Premium | 30 |
| 104 | Free | 10 |
| 105 | Enterprise | 100 |
| 106 | Enterprise | 150 |
| plan_type | total_storage |
|---|---|
| Enterprise | 250 |
| Free | 15 |
| Premium | 80 |
SQL Editor
| plan_type | total_storage |
|---|---|
| Enterprise | 250 |
| Free | 15 |
| Premium | 80 |
Hints
Solution
Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.
SELECT plan_type, SUM(storage_used_gb) AS total_storage FROM storage GROUP BY plan_type;
Explanation
Read the expected output columns to determine the final grain.
Aggregate or rank the input rows to calculate the requested metric.
Filter, sort, and alias the final columns to match the output.
Related Questions