ksa
Posts: 27
|
Posted: 06/02/2015, 11:13 AM |
|
I'm trying to make a grid where the sort order is based on the number of times a value appears in the database table.
Let me explain: users can add records to the database. Each record that they add contains the username of the submitter. Now I want to show the usernames sorted by how many records they submitted, like a top 10 list of submitters. That is:
user32 submitted 122 records
user55 submitted 109 records
user21 submitted 98 records etc....
I understand that I need to group the list by username, but how do I make the usernames appear in that order and also include the number of records each of them submitted?
Seems like it should be simple, but I'm unable to figure it out.
|
|
|
saseow
Posts: 744
|
Posted: 06/02/2015, 11:25 AM |
|
Try making a view or temp table that is already grouped by user and then do a sort on that.
|
|
|
ksa
Posts: 27
|
Posted: 06/04/2015, 9:26 AM |
|
Thanks for the reply. It's a little too unspecific for me to understand.
|
|
|
saseow
Posts: 744
|
Posted: 06/04/2015, 10:24 PM |
|
The group will always be automatically sorted so, to get them sorted by the number of records you will have to create either a temp table or a view.
So, lets say you are going to use a view. Select into the view something like "select count(id) as cnt from yourtable group by user."
Then you can select into your grid the view records and sort by 'cnt' descending.
|
|
|
MichaelMcDonald
Posts: 640
|
Posted: 06/05/2015, 5:54 AM |
|
I can't post it for some reason so I pm'ed you with it.
It probably looks like an attempt at injection :)
_________________
Central Coast, NSW, Australia.
|
|
|
ksa
Posts: 27
|
Posted: 06/07/2015, 4:00 AM |
|
Thank you for the replies, here and in private. I haven't had a chance to try any of it yet, but I will. I'm sure the solution is there.
|
|
|