Find power users who uploaded more than 500 MB in a 30-day window
Company: Dropbox
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
Find the power users of a file storage service: users whose total uploaded file size from `2024-01-01` to `2024-01-30` (both days inclusive) is strictly greater than 500 MB. Return each such user's id, username and total upload volume for that window.
### Input Table(s)
`users`, primary key `user_id`:
| Column | Type | Meaning |
|---|---|---|
| user_id | INT | Unique user id |
| username | VARCHAR(100) | Display name, NOT NULL |
| email | VARCHAR(200) | Email address, NOT NULL |
| signup_date | DATE | Date the account was created, NOT NULL |
`file_uploads`, primary key `upload_id`, with `user_id` a foreign key to `users.user_id`:
| Column | Type | Meaning |
|---|---|---|
| upload_id | INT | Unique upload id |
| user_id | INT | User who uploaded the file |
| file_name | VARCHAR(200) | Name of the uploaded file, NOT NULL |
| file_size_mb | DECIMAL(10,2) | File size in megabytes, NOT NULL, always positive |
| upload_date | DATE | Calendar date of the upload, NOT NULL |
### Output Contract
- Columns, in this order: `user_id`, `username`, `total_uploaded_mb`.
- `total_uploaded_mb` is the sum of `file_size_mb` over the user's uploads in the window, kept at the two decimal places of the source column with no further rounding.
- One row per qualifying user.
- Sort by `total_uploaded_mb` descending, then by `user_id` ascending.
### Example
`users`:
| user_id | username | email | signup_date |
|---|---|---|---|
| 1 | alice | alice@example.com | 2023-11-02 |
| 2 | bob | bob@example.com | 2023-12-15 |
| 3 | carol | carol@example.com | 2024-01-05 |
| 4 | dave | dave@example.com | 2023-08-20 |
| 5 | eve | eve@example.com | 2023-10-01 |
`file_uploads`:
| upload_id | user_id | file_name | file_size_mb | upload_date |
|---|---|---|---|---|
| 101 | 1 | video.mp4 | 450.00 | 2024-01-03 |
| 102 | 1 | slides.pdf | 120.50 | 2024-01-30 |
| 103 | 2 | backup.zip | 300.00 | 2024-01-10 |
| 104 | 2 | raw.tar | 250.00 | 2024-01-31 |
| 105 | 3 | photos.zip | 320.25 | 2024-01-12 |
| 106 | 3 | music.zip | 250.25 | 2024-01-20 |
| 107 | 4 | archive.zip | 500.00 | 2024-01-15 |
| 108 | 4 | old.iso | 700.00 | 2023-12-31 |
| 109 | 5 | design.psd | 800.00 | 2024-01-01 |
Expected result:
| user_id | username | total_uploaded_mb |
|---|---|---|
| 5 | eve | 800.00 |
| 1 | alice | 570.50 |
| 3 | carol | 570.50 |
Eve's single upload on the first day of the window gives 800.00. Alice's upload on 2024-01-30 still counts, so she has 450.00 + 120.50 = 570.50. Carol also has 320.25 + 250.25 = 570.50, and the tie is broken by `user_id`, which puts alice (1) before carol (3). Bob's 2024-01-31 upload falls outside the window and leaves him at 300.00. Dave's December upload does not count, so his window total is exactly 500.00, which is not strictly greater than 500.
### Constraints and Clarifications
- `users` has at most 10,000 rows and `file_uploads` at most 100,000 rows.
- `upload_date` has no time part, so the window is the 30 calendar days from 2024-01-01 through 2024-01-30.
- The threshold is strict: a user whose window total is exactly 500.00 is left out.
- Users with no uploads in the window do not appear in the result.
- A user can have many uploads, including several on the same day or with the same file name. Every row counts toward the total.
- Usernames are not guaranteed to be unique, so identify users by `user_id`.
- An upload with a NULL `user_id` belongs to no user and is ignored.
```hint Window edges
Check what your date filter does with an upload dated 2024-01-30 and one dated 2024-01-31.
```
Overview: Write a SQL query that finds users whose total upload size over a fixed 30-day window is above 500 MB and returns each user's total, sorted by volume. It tests joins, inclusive date range filters, GROUP BY with HAVING, and deterministic tie-breaking.