Premium problem49. Repeat Purchase Within 30 Days

Medium Locked

orders(order_id, user_id, ordered_at)

Among users whose first ever purchase happened in 2026, return repeat_30d_pct: the percentage who bought again within 30 days of that first purchase, rounded to two decimals.

"First ever" means first in the whole table, not first in 2026. A user whose earliest order is from 2025 is out of the denominator entirely, even if they ordered again in 2026.

Tables

orders

order_id  user_id  ordered_at
--------  -------  -------------------
1         10       2026-01-05 10:00:00
2         10       2026-01-20 10:00:00
3         11       2026-02-01 10:00:00
4         11       2026-03-13 10:00:00
5         12       2025-12-01 10:00:00
6         12       2026-04-01 10:00:00
7         12       2026-04-05 10:00:00
8         13       2026-05-01 10:00:00

Expected result

repeat_30d_pct
--------------
33.33

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query