LEAD: Detect Days Where Sales Will Increase Next Day
SQL coding challenge · Difficulty: easy · +50 XP
Problem
The automated buying system should pre-order stock on any day where tomorrow's sales are expected to be HIGHER than today's. Find those days.
Tables
Table: daily_sales
| sale_id | day_name | amount | | 1 | Mon | 100 | | 2 | Tue | 200 | | 3 | Wed | 300 | | 4 | Thu | 400 | | 5 | Fri | 500 |
Expected Output
| sale_id | day_name | amount | next_day_sales | | 1 | Mon | 100 | 200 | | 2 | Tue | 200 | 300 | | 3 | Wed | 300 | 400 | | 4 | Thu | 400 | 500 |
- Return:
sale_id,day_name,amount,next_day_sales - Only rows where
next_day_sales > amount - Exclude the last row (NULL next-day data)
- Hint: Compute LEAD() in a subquery first, then filter