Hi folks, just wanna share a few sql questions I had on a recent Amazon Data Scientist phone interview
there are 2 tables: STREAMS and TITLES
STREAMS table
USER_ID
TITLE_ID
STREAM_TIMESTART
STREAM_MINUTES
Key for this table is (USER_ID,TITLE_ID,STREAM_TIMESTART)
TITLES table
TITLE_ID
GENRE
NAME
LAUNCH_DATE
Key for this table is TITLE_ID- Find the number of times of each movie (title) was streamed and the total minutes streamed and the movie's genre in the month of December 2018.
My solution: Straightforwardjoinandgroup by - Find the name and title id of the first movie streamed by each user each day.
My solution: Window function parition byUSER_IDanddate(STREAM_TIMESTART)and order bySTREAM_TIMESTARThere, takingrow_number()==1. - Find the total minutes streamed for each movie within the first 28 days since the movie's launch date.
My solution: I did ajoinwith a filterLAUNCH_DATE + INTERVAL 28 DAYS >= date(STREAM_TIMESTART)here but the interviewer did not seemed to like/understand this approach and kept asking me for an alternative approach. I guess he found it unintuitive? Anyone else got another idea please?
Comments (8)


