Getting count() for each specific group

Discussion in 'MySQL' started by PoPSiCLe, Apr 3, 2014.

  1. #1
    Hi. I have a query like this:
    
    SELECT t1.fullname,t1.user_id,t3.name FROM persdb_users t1 LEFT JOIN persdb_user_groups t2 ON t1.user_id = t2.user_id LEFT JOIN persdb_groups t3 ON t2.group_id = t3.group_id WHERE registered like '%YEAR-MONTH%' AND active = 1 ORDER BY t3.name
    
    Code (markup):
    What it does is it gets the users full name and group name based on the selected year and month (substitute the YEAR and MONTH for actual values) - I'd like to be able to do a count for each group (t3.name) - how would I do that within this query?
     
    PoPSiCLe, Apr 3, 2014 IP
  2. Zoidrums

    Zoidrums Greenhorn

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    11
    #3
    Did you try this ?

    SELECT t3.name, count(*)
    FROM persdb_users t1
    LEFT JOIN persdb_user_groups t2
    ON t1.user_id = t2.user_id
    LEFT JOIN persdb_groups t3
    ON t2.group_id = t3.group_id
    WHERE registered like '%YEAR-MONTH%'
    AND active = 1
    GROUP BY t3.name
     
    Zoidrums, Feb 9, 2017 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    The question is 3 years old... I don't really remember what I did to solve the problem, but I'm pretty sure it has been solved. I will do a check of the code-base and see if I can find out how/what I did to fix it, or if I just ended up doing something else alltogether.
     
    PoPSiCLe, Feb 9, 2017 IP