Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Counting distinct number of instances, per instance

0 views
Skip to first unread message

Jason Carlton

unread,
Nov 2, 2009, 3:09:52 PM11/2/09
to
I have a message board, and I'm wanting to display a count of how many
posts have been made by each username, sorted from highest to lowest.

This will count the total number, but not by username:

SELECT DISTINCT COUNT(username) FROM forum_posts

How do I list the total by username? Like:

John 48
Sarah 29
James 18


TIA,

Jason

J.O. Aho

unread,
Nov 2, 2009, 3:31:10 PM11/2/09
to


SELECT COUNT(username) as nums, username FROM forum_posts GROUP BY username
ORDER BY nums DESC

--

//Aho

Jason Carlton

unread,
Nov 2, 2009, 4:05:34 PM11/2/09
to

That's perfect, thank you!

For anyone reading this in the future, the above code listed all
usernames at once, on the same page. In my case, I had around 70,000
usernames, so it took awhile for my browser to load them all. So you
may want to add a limit, if you have a high number of results.

Thanks again, Aho,

Jason

0 new messages