-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday-05.sql
More file actions
34 lines (31 loc) · 921 Bytes
/
day-05.sql
File metadata and controls
34 lines (31 loc) · 921 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
25
26
27
28
29
30
31
32
33
34
-- SQL Advent Calendar - Day 5
-- Title: Elf Vacation Status
-- Difficulty: medium
--
-- Question:
-- Some elves took time off after the holiday rush, but not everyone has returned to work. List all elves by name, showing their return date. If they have not returned from vacation, list their return date as "Still resting".
--
-- Some elves took time off after the holiday rush, but not everyone has returned to work. List all elves by name, showing their return date. If they have not returned from vacation, list their return date as "Still resting".
--
-- Table Schema:
-- Table: elves
-- elf_id: INT
-- elf_name: VARCHAR
--
-- Table: vacations
-- elf_id: INT
-- start_date: DATE
-- return_date: DATE
--
-- My Solution:
SELECT
e.elf_name,
COALESCE(
v.return_date,
'Still resting'
) AS return_status
FROM
elves AS e
LEFT JOIN
vacations AS v
ON e.elf_id = v.elf_id;