December 10, 2015 at 10:39 am
Hello,
I have the following question:
My data set is:
id: - number:
1 - 20
2 - 11
3 - 20
4 - 8
5 - 11
6 - 4
First, I want to group by number and order by the count of that group. So I have the following select statement:
SELECT number, count(*) as numbercount FROM numbers group by number order by numbercount desc
The result SHOULD be:
number: - numbercount:
20 - 2
11 - 2
8 - 1
4 - 1
So I would like to order by numbercount desc. That works, but after that, I would like to order by the smallest id that exists in that group. Number 20 is the first number that counts 2, so number 20 must be the first result. After that, number 11 counts 2, so it must be after number 20.
The problem is that I just don't know how to order that groups with the same numbercount.
I hope I explained my problem clear.
Thank you very much in advance!
December 10, 2015 at 10:43 am
I think this post is in the wrong section. Please remove it. Sorry.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply