Week-over-Week Growth Percentage

SQL coding challenge · Difficulty: medium · Topic: Window Functions · +100 XP

Problem

Sales are reported weekly, each row labelled with the Monday that starts the week. Show how each week compares with the one before it.

Schema — `weekly_sales`

| Column | Type |
| --- | --- |
| week_start | DATE |
| sales | INT |

Example Input — `weekly_sales`

| week_start | sales |
| --- | --- |
| 2024-06-03 | 700 |
| 2024-06-10 | 840 |
| 2024-06-17 | 790 |
| 2024-06-24 | 1000 |

Expected Output

| week_start | sales | prev_week_sales | wow_growth_pct |
| --- | --- | --- | --- |
| 2024-06-03 | 700 | NULL | NULL |
| 2024-06-10 | 840 | 700 | 20.00 |
| 2024-06-17 | 790 | 840 | -5.95 |
| 2024-06-24 | 1000 | 790 | 26.58 |

Explanation

The earliest week has nothing to compare against, so its growth is NULL.

Notes

What this SQL challenge teaches you

“Week-over-Week Growth Percentage” is a medium-level SQL challenge focused on Window Functions. Working through it gives you hands-on practice with LAG, OVER, Growth, Window Functions — 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

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:

  1. ORDER BY week_start inside OVER puts the weeks in order.
  2. LAG gives the previous week; the first week has no previous week.
  3. (current - previous) * 100.0 / previous, wrapped in ROUND(..., 2).

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

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 medium and covers Window Functions.

Solve this challenge free on PySpark.in