SQL
Lab
Microsoft Microsoft Interview Question 10

Storage
Usage
by Subscription

Calculate total storage used per subscription plan.

Table Schema

Inspect
Table

interactive
ColumnType
user_idinteger
plan_typevarchar
storage_used_gbdecimal

Sample Data

Input
Output

Sample Input: storage
user_idplan_typestorage_used_gb
101Free5
102Premium50
103Premium30
104Free10
105Enterprise100
106Enterprise150
Expected Output
plan_typetotal_storage
Enterprise250
Free15
Premium80

SQL Editor

Run
Query

postgresql
Waiting for query

plan_typetotal_storage
Enterprise250
Free15
Premium80

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

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

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving