medium10 pts · first answer countssqlwindow-functions
Day-over-day change with LAG
daily has revenue 100 on 03-01, 130 on 03-02 and 90 on 03-03. What does the query return, in date order?
SELECT d, revenue - LAG(revenue) OVER (ORDER BY d) AS change FROM daily ORDER BY d;
Discussion 0
Join free to post in the discussion.
Related questions
- Purpose of a primary keyData Engineer
- Row count of a LEFT JOINData Engineer
- Filtering with = NULLData Engineer
- COUNT(*) vs COUNT(column)Data Engineer
- Filtering groups with HAVINGData Engineer
- Adding a number to NULLData Engineer
- Orders pointing to missing customersData Engineer
- Upserting into a target tableData Engineer