I am trying to understand this problem - it seems pretty direct
The table below shows which user has watched the video,
topic_user_id | topic_id | user_id
1 | 10 | 3
2 | 10 | 4
3 | 11 | 5
4 | 11 | 3
5 | 12 | 6
6 | 13 | 6
7 | 14 | 7
8 | 11 | 8
9 | 11 | 9
10 | 14 | 10
11 | 15 | eleven
12 | 16 | eleven
13 | 17 | eleven
Now, to find out how many users have watched a particular video, I have the following query.
HOW MANY USERS SEE A SPECIFIC VIDEO
select count (distinct (user_id)) as 'Number of Users', topic_id from topic_user
where user_id is not null
group by topic_id
Exit
Number of Users | topic_id
2 | 10
4 | eleven
1 | 12
1 | thirteen
2 | 14
1 | fifteen
1 | 16
1 | 17
Read as: 2 users watched topic 10, 4 watched topic 11 and so on
It works great. But I am looking to find:
How many users watched 1 video
How many users watched 2 videos
How many users watched 3 videos
The result should be something like
Number of Users | Number of videos watched
6 | 1
2 | 2
1 | 3
Read as - 6 people watched only 1 video, 2 people watched 2 videos and so on.
You need help.
Thank you in advance
source share