1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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?
    SEMrush
     
    PoPSiCLe, Apr 3, 2014 IP
    SEMrush
  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,626
    Likes Received:
    719
    Best Answers:
    151
    Trophy Points:
    420
    #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