If you know that salaryplus will always be more than salaryminus , you can do
order by coalesce(salaryplus, salaryminus, 0)
coalesce will return the first value that is not null or (in this example) 0 if both values ββare zero.
Otherwise, do the following:
order by greatest(ifnull(salaryminus,0), ifnull(salaryplus,0))
This will apply to both salaryminus and salaryplus to 0 if they are zero, and will be ordered by the larger of the two.
Ian clelland
source share