Working on a dataset containing users watching content from multiple genres. I want to come up with combination of genres (group of 2 genres) and count of users watching content from both genres.
On self joining and getting the data below is the output I’m getting
output_image_here
Ideally I want one row for each combination. How to remove the additional row from my output?
select genre1, genre2, count(uid) as User_count
from( select a.uid, a.content_genre as genre1, b.content_genre as genre2 from ( select content_genre, uid from table group by 1,2)a
left join
( select content_genre, uid
from table group by 1,2
)b o
n a.uid=b.uid
and a.content_genre <> b.content_genre
)
group by 1,2
order by user_count desc
Vinay Dalal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.