Query id most often repeated

1

I have two tables, one user and one visitas . In the visitas table I keep the ID of the user who was visited and who visited.

How to make a query where I leave the users in order of more number of visits? I do not keep the total anywhere.

Any tips?

    
asked by anonymous 28.03.2016 / 17:17

1 answer

3

Just select with totalizing function

select userid, count(*)
from visitas
group by userid
order by 2 desc

To sort use a order by , so the data appears with the most visited users first.

    
28.03.2016 / 17:20