-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday-15.sql
More file actions
22 lines (19 loc) · 776 Bytes
/
day-15.sql
File metadata and controls
22 lines (19 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
-- SQL Advent Calendar - Day 15
-- Title: The Grinch's Mischief Tracker
-- Difficulty: hard
--
-- Question:
-- The Grinch is tracking his daily mischief scores to see how his behavior changes over time. Can you find how many points his score increased or decreased each day compared to the previous day?
--
-- The Grinch is tracking his daily mischief scores to see how his behavior changes over time. Can you find how many points his score increased or decreased each day compared to the previous day?
--
-- Table Schema:
-- Table: grinch_mischief_log
-- log_date: DATE
-- mischief_score: INTEGER
--
-- My Solution:
select log_date, mischief_score,
mischief_score-lag(mischief_score) over(order by log_date) as score_change
from grinch_mischief_log
order by log_date;