Peak Sales Day and Its Share of Total
SQL coding challenge · Difficulty: easy · Topic: Aggregation · +50 XP
Problem
Find the single best sales day in the period, and show what share of the period's total sales it accounted for.
Schema — `daily_traffic`
| Column | Type | | --- | --- | | order_date | DATE | | sales | INT |
Example Input — `daily_traffic`
| order_date | sales | | --- | --- | | 2024-06-01 | 100 | | 2024-06-02 | 150 | | 2024-06-03 | 120 | | 2024-06-04 | 180 | | 2024-06-05 | 200 | | 2024-06-06 | 160 | | 2024-06-07 | 140 | | 2024-06-08 | 220 | | 2024-06-09 | 190 | | 2024-06-10 | 210 |
Expected Output
| order_date | sales | share_pct | | --- | --- | --- | | 2024-06-08 | 220 | 13.17 |
Explanation
Return exactly one row. The share is that day's sales as a percentage of the sum of all days, rounded to 2 decimals — so if the best day sold 220 out of 1670 sold in total, its share is 13.17.
Notes
- Return:
order_date,sales,share_pct(2 decimals) — one row only - Row order is not graded; the example is ordered for readability
- Same problem in PySpark: [Peak Sales Day and Its Share of Total (PySpark)](/challenges/peak-sales-day-and-its-share-of-total-pyspark)
What this SQL challenge teaches you
“Peak Sales Day and Its Share of Total” is a easy-level SQL challenge focused on Aggregation. Working through it gives you hands-on practice with ORDER BY, LIMIT, Subquery, Aggregation — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.
Concepts covered
- ORDER BY
- LIMIT
- Subquery
- Aggregation
How to approach it
If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:
- ORDER BY sales DESC with LIMIT 1 gives the best day.
- The total comes from a subquery: (SELECT SUM(sales) FROM daily_traffic).
- Multiply by 100.0 before dividing, or integer division rounds to 0.
How to practise it on PySpark.in
Open the challenge, write your SQL query in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.
Related SQL challenges
- Find Duplicate Emails
- HR: Average Salary by Department
- Logistics: Count Shipments by Status
- Count Total Orders Placed by Each Customer
- Find Average Order Amount for Each Customer
- Find Customers Who Placed More Than 5 Orders (HAVING)
Frequently asked questions
Do I need to install Spark or a database to solve this?
No. The SQL environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.
Is this challenge free?
Yes - the problem, the sample dataset, the hints and unlimited test runs are free.
What level is it?
It is rated easy and covers Aggregation.