ORDER BY ranking DESC WHERE ranking > 0
Does anybody know if it's possible to ORDER BY something conditionally
Basically, I want to order by `ranking` ASC where `ranking` isn't '0' , and then display the '0' ones afterwards.
I know it's easily done with more than one query but I'm interested to know if it's possible with just one query.
Currently it's:
0
0
0
0
1
5
38
192
And I want:
1
5
38
192
0
0
0
0
ORDER BY ranking DESC WHERE ranking > 0
Nope.. doesn't work (and I already tried it before).
how the type of ranking ?
I'm not sure what you mean.. the column type is TINYINT, though.
sorry i didn't gave you a good answer, also my question is written badly. I can make it display this:
1
5
28
192
Without 0, it will be like thisCode:SELECT * FROM `table` WHERE rank > 0 ORDER BY rank ASC
I want the 0, but I want them to be ordered after the other numbers.
It's probably not possible with 1 query (I know definitely it is with 2) - but that's what I'm after.
use COUNT(*) to get the total number of rows, then use numrows to get rows that are NOT 0, then subtract numrows from COUNT(*) and you have the number of entries that are 0.
Bookmarks