-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday-18.sql
More file actions
24 lines (21 loc) · 930 Bytes
/
day-18.sql
File metadata and controls
24 lines (21 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- SQL Advent Calendar - Day 18
-- Title: 12 Days of Data - Progress Tracking
-- Difficulty: hard
--
-- Question:
-- Over the 12 days of her data challenge, Data Dawn tracked her daily quiz scores across different subjects. Can you find each subject's first and last recorded score to see how much she improved?
--
-- Over the 12 days of her data challenge, Data Dawn tracked her daily quiz scores across different subjects. Can you find each subject's first and last recorded score to see how much she improved?
--
-- Table Schema:
-- Table: daily_quiz_scores
-- subject: VARCHAR
-- quiz_date: DATE
-- score: INTEGER
--
-- My Solution:
SELECT DISTINCT subject,
FIRST_VALUE(score) OVER (PARTITION BY subject ORDER BY quiz_date) AS first_score,
LAST_VALUE(score) OVER (PARTITION BY subject ORDER BY quiz_date
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS last_score
FROM daily_quiz_scores;