Completion rate by content type

conditional logic

Completion rate by content type

Netflix SQL Interview Question

Netflix's product team wants to compare how often people finish movies with how often they finish episodes of a series. A view counts as finished when the person watched at least 90% of the title's runtime.

For each content_type, find the percentage of views that were finished, as completion_rate_pct, rounded to 1 decimal place. Use all views of that content type as the total.

Asked of

  • Data Analyst
  • Product Analyst
  • Data Scientist
  • BI Analyst

viewing_activityTable16 rows

Column NameType
view_idBIGINT
profile_idBIGINT
title_idBIGINT
countryVARCHAR
watch_dateDATE
minutes_watchedBIGINT

titlesTable6 rows

Column NameType
title_idBIGINT
title_nameVARCHAR
content_typeVARCHAR
genreVARCHAR
runtime_minutesBIGINT

viewing_activityExample Input

view_idprofile_idtitle_idcountrywatch_dateminutes_watched
110011United States2024-08-01118
210024United States2024-08-0158
310034United States2024-08-0230
410043United States2024-08-0245
510051Brazil2024-08-0260
610066Brazil2024-08-0352
710076Brazil2024-08-0352
810082Brazil2024-08-0392
910095India2024-08-04101
1010103India2024-08-0420

titlesExample Input

title_idtitle_namecontent_typegenreruntime_minutes
1Midnight HeistMovieThriller118
2Ocean DeepMovieDocumentary92
3Kitchen WarsSeriesReality45
4The Last ColonySeriesSci-Fi58
5Laugh TrackMovieComedy101
6Crown of AshSeriesDrama52

Example Output

content_typecompletion_rate_pct
Movie75
Series66.7

Explanation

There are four movie views in the example. One person watched only 60 of Midnight Heist's 118 minutes, which is less than 90%, so that view is not finished. The other three movie views were finished, which gives 75.0%. Four of the six series views were finished, which gives 66.7%.

The example above is a small slice of the data. Your query runs against the full tables.