Home > other >  how to get the total number of users depending on a condition mysql?
how to get the total number of users depending on a condition mysql?

Time:05-24

I want to get the total number of users who have seen 7 videos. I have tried this way but it groups me by user the videos they have seen

SELECT users.name,count( lecciones_users.uuid ) AS total_see_all_video FROM lecciones_users 
LEFT JOIN users ON users.uuid=lecciones_users.uuid 
GROUP BY lecciones_users.uuid,users.name 

query response

query response

the answer I need would be total_see_all_video = 9

CodePudding user response:

-- Count the users...
select count(*) as total_see_all_video
from users u
where 
      -- ... if the number of videos watched is 7
      7=(select count(*) 
         from lecciones_users lu
         where lu.uuid=u.uuid)
  • Related