Turning Learners Into Developers
Codekilla
CODEKILLA
Medium
SQL-W04sql

Day-Over-Day Sales % Change

Problem

Given `daily_sales(d, total)` (continuous days), output (d, total, prev_total, pct_change). pct_change = NULL on day 1.

Input
Daily sales sorted by d.
Output
d, total, prev_total, pct_change
Constraints
1 ≤ rows ≤ 10^5
Sample input
(2024-01-01,100),(2024-01-02,120),(2024-01-03,90)
Sample output
...,(120,100,20.0),(90,120,-25.0)
Explanation
LAG(total) over the date window gives yesterday's value.
window-fnlaggrowth@Snowflake
Visible test cases
in: see
out: ...
Your solution — run it, use AI if stuck
sql