#539
File Download Event Summary
HARDDatabasePOSTGRESQL
Problem Description
As part of the monthly analytics of a file storage service, you need to produce a summary of collected file download events in June 2022.
You have one table: `events` with columns `dt` (event datetime as `VARCHAR(19)` in `YYYY-MM-DD HH:MM:SS` format), `mime` (MIME type), `filename` (file name), and `filesize` (file size in bytes).
Return the following columns:
- `mime`: the MIME type
- `extension`: a comma-separated list of distinct file extensions found for that MIME type, sorted in ascending alphabetical order. The extension is the part of the filename after the last dot.
- `files`: the total number of files for that MIME type
- `total`: the total size of all files for that MIME type, rounded to two decimal places, with the unit of measure appended. Use `GiB` if the total is 1 GiB (1,073,741,824 bytes) or more; otherwise use `MiB` (1 MiB = 1,048,576 bytes). Format as `X.XX MiB` or `X.XX GiB`.
Only events from June 2022 should be included in the report.
Sort the result in descending order by the raw total size (in bytes) of files for each MIME type.
Topics
conditional logicaggregationstring functions
Asked at Companies
amazon
Solve This Problem
Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.
Start Solving →