I need a SQL statement, the requirement is: there is a table, which has two columns: ID, Owner_ID; I inserted several records, for example:
ID Owner_ID
0 0
1 0
2 1
3 1
4 2
5 3
6 3
7 3
8 3
9 0
Now I need a SQL statement, which returns a ID list sorted by the number of rows owned by different user, from largest to smallest. In this example, owner 3 has four rows; owner 0 has three rows, owner 1 has two rows; and owner 2 has one rows. the result should be
ID Owner_ID
5 3
6 3
7 3
8 3
0 0
1 0
9 0
2 1
3 1
4 2
I think I should use the aggregate function count, does anybody have an idea?
I am using HSQLDB.
Thanks in advance!!