Forum

Posted by Mandeep, Jan. 15, 2023, 2:24 a.m.

182. Top 5 content by number of watchers

I am trying to solve this problem but I am getting this error with this query

with tmp as (

  select na.account_id,
         nc.content_id,
         sum(nd.duration) as total_watched, 
         nd.date as date_watched
  from netflix_account na
  inner join netflix_daily_streaming nd on
               na.account_id = nd.account_id
  inner join netflix_content nc on
               nc.content_id = nd.content_id
  where datediff(nd.date,nc.release_date) < 28
  group by na.account_id, nc.content_id
  having sum(nd.duration) > 600
 
  ),

tmp2 as ( 
  select content_id, 
          count (account_id) as uu_cnt         
  from tmp
  group by content_id
  )

select content_id,
        uu_cnt
from tmp2
order by uu_cnt desc
limit 5;

 

 

I am getting the error 
Bad Request

 

Answers

Hey Mandeep,

Thanks for your question, this is caused by the space in between a MySQL function and the parenthesis.

I removed the space between COUNT function and the "(" and it worked.

Mind trying again?

--Leon

SQLPad user avatar

Leon (949)

Jan. 21, 2023, 12:10 p.m.