sql - How can I order results which have some value equals zero in the end, while other results are ascending? -


let me explain: need sort list in ascending order, while results leave less 0 @ end.

example:

**field**   2   5   15   19   0   -5   -19  

i think can join result of 2 queries using union, want using one, possible?

any answer telling how order thay way appreciated.

use following order @ end of normal query (no union)

order (case when field>0 0 else 1 end), field 

or, if database system's sql flavor supports implicit conversion of booleans integers:

order (field <= 0), field 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -