Problem query mysql

0

I have a problem with a query, I have never actually made this kind of query, I've tried but I still can not get what I want, so I explain what I want to do with the following table.

I have this table, as you can see in user_ad the users repeat themselves, since they are parent users that add child users, for example, danielad I add pepe, yhonier, I fight, etc ... what I want to do is that with base the user_ad show me the number of users that is in charge of each parent user, I mean something like danielle 4, andresad 2, angiead 3, paolaad 3, in my case you can make a count like that?

    
asked by zereft 16.12.2018 в 01:07
source

1 answer

1

If it is to tell the parent users, it would be like this:

SELECT COUNT(nombre) FROM usuarios WHERE usuario_ad = 'danielad';  
SELECT COUNT(nombre) FROM usuarios WHERE usuario_ad = 'andresad';  
SELECT COUNT(nombre) FROM usuarios WHERE usuario_ad = 'angiead';  
SELECT COUNT(nombre) FROM usuarios WHERE usuario_ad = 'paolaad';  

On a single line:

SELECT COUNT(nombre), usuario_ad FROM usuarios GROUP BY usuario_ad;
    
answered by 16.12.2018 / 01:48
source