SQL select to find the identifier that most

The main question of the SQL query is

I have a table (myUsers) that contains the column "UserID". The same user ID can be displayed once many times in these lines. I am looking for a query that will return me the specific user IDs that will be displayed most in this table, as well as their score. Any thoughts?

Thanks in advance!

+4
source share
2 answers
select UserID, count(UserID) from myUsers group by UserID order by count(UserID) desc 
+28
source
 DECLARE @THRESHOLD INT SET @THRESHOLD = 20 SELECT UserID, COUNT(*) FROM MYUSERS GROUP BY UserID HAVING COUNT(*) > @THRESHOLD ORDER BY COUNT(*) DESC 

EDIT: I moved from where I was and completely forgot about it. :)

+2
source

All Articles