Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

SECTION 1: SQL

Given the two data tables below, please provide SQL queries for the following questions.

Viewership Table: fact_view Series Metadata Table: dim_video


Field Data Type Field Data Type

video_id varchar video_id varchar

session_id varchar episode_name varchar

date timestamp episode_number int

user_id varchar season_number int

seconds_watched int series_name varchar

runtime_seconds int

genre varchar

1. How many unique viewers did Game of Thrones & Westworld garner in the past 7 days? [Hint: use
series_names]

select
series_name,
count(distinct user_id) as num_viewers
from
fact_view
left join dim_video on fact_view.video_id = dim_video.video_id
where series_name in ('Game of Thrones','Westworld')
and datediff(day,date,current_date) <= 7
group by 1

2. What is the average completion rate (seconds watched divided by runtime) for the first episode of every
series?

select
series_name,
avg(seconds_watched/ runtime_seconds) as avg_completion_rate
from
fact_view
left join dim_video on fact_view.video_id = dim_video.video_id
where episode_number = 1 and season_number = 1
group by 1

3. What is the 2nd most watched episode per genre in terms of minutes watched?

with time_watched as (

1 of 2
select
genre,
episode_name,
seconds_watched/60 as mins_watched,
rank() over (partition by genre order by mins_watched desc) as time_rank
from
fact_view
left join dim_video on fact_view.video_id = dim_video.video_id)

select *
from time_watched where time_rank = 2

4. We are interested in comparing the difference in time spent streaming in the summer months as opposed
to the winter months. Calculate the total time each user spent streaming in the summer months and
winter months as well as the percent change between the two. Percent change can be computed as
(winter-summer)/summer. Summer can be defined as the months June, July and August. Winter is
defined as the months December, January and February.

select
user_id,
sum(iff(month(date) in (6,7,8), seconds_watched, 0) summer_time_watched,
sum(iff(month(date) in (12,1,2), seconds_watched, 0) winter_time_watched,
(winter_time_watched-summer_time_watched)/summer_time_watched as percent_change
from fact_view
group by 1

select
user_id
avg(case
when (month(date) >= 6 and month(date) <= 8) then seconds_watched
else null
end) as summer_time_watched,
avg(case
when (month(date) in (12,1,2)) then seconds_watched
else null
end) as winter_time_watched,
(winter_time_watched-summer_time_watched)/summer_time_watched as percent_change

from
fact_view

5. Find the average amount of time, in days, it takes a user to complete each season of ‘Friends’. Season
completion is defined as a completing at least 90% of the season runtime. Time to completion can be
considered as the difference between the day the user first to the last day they watched the season.
with season_runtime as (
select
season_number,
sum(runtime_seconds) as season_runtime

2 of 2
from
dim_video
where series_name = 'Friends'),

viewership as (
select
user_id,
season_number,
sum(seconds_watched) as season_watched,
min(date) as first_watch_date,
max(date) as last_watch_date
from
fact_view
left join dim_video on fact_view.video_id = dim_video.video_id
where series_name = 'Friends'
group by 1,2)

select
season_number,
avg(date_diff(day,first_watch_date,last_watch_date)) as days_to_complete
from viewership v
left join season_runtime sr on v.season_number = sr.season_number
where season_watched >= 0.9*season_runtime

SECTION 2: LOOKER

1. When would you use Merged Results in Looker?


a. You would use Merged results when you want to join results from two different explores on a
common field, or if you want to join the results of two queries with different filter parameters.

2. Explain the difference between a persisted and an ephemeral derived table in Looker. In which cases
would you want to use one versus the other?
a. Persisted derived tables are stored as temporary tables in the database that can be queried like
regular tables. Ephemeral derived tables point to a SQL query that runs every time a field from
the derived table is referenced. You want to use a PDT when the SQL query has a long run time
or is queried often. You can use an ephemeral derived table when the query is short, fast, not
queried often, or the query contains liquid parameters.

3. Name 3 parameters you can use to persist a derived table


a. Persist_for, data_group_trigger, sql_trigger_value

4. Name two ways to display a value with the following format: 70.0%. Include the appropriate parameters
for each format.
a. Value_format: “0.0%”
b. Value_format_name: percent_1

Debug dashboard
Stakeholders

3 of 2
Experience with visualization tools
Years of experience with SQL
Tech stack
What is the pipeline you work with (DE vs stakeholders)

4 of 2

You might also like