-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadback.sql
33 lines (30 loc) · 1.16 KB
/
readback.sql
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
COPY (
WITH shows_by_type AS(
select e.id as episode_id, s.name as show_name, e.show_type from episodes e join freeform_shows s on s.id = e.show_id where e.show_type = 'FreeformShow'
UNION ALL
select e.id as episode_id, s.name as show_name, e.show_type from episodes e join specialty_shows s on s.id = e.show_id where e.show_type = 'SpecialtyShow'
UNION ALL
select e.id as episode_id, s.name as show_name, e.show_type from episodes e join talk_shows s on s.id = e.show_id where e.show_type = 'TalkShow'
),
public_dj_names as (
select
djs.id as dj_id,
CASE
WHEN dj_name=NULL AND real_name_is_public=TRUE THEN name
ELSE dj_name
END as dj_name
from djs
)
select
songs.at as played_at,
songs.name as song_name,
songs.artist,
songs.album,
songs.label,
CASE
WHEN shows.show_type='SpecialtyShow' THEN 'rotating hosts'
ELSE public_dj_names.dj_name
END as dj_name,
shows.show_name as show_name
from songs inner join episodes e on songs.episode_id = e.id inner join public_dj_names on e.dj_id = public_dj_names.dj_id join shows_by_type shows on e.id = shows.episode_id order by songs.at
) TO STDOUT WITH CSV HEADER;