Reputation: 107
I have mysql table that looks like below :
In this table there are minus and plus value. I wants all record in dropdown in a format like.
I need to show first as zero than minus value in descending order and positive value in acsending order. So what query should I have to write?
For example :
0.00
-1
-2
...
...
...
1
2
3
...
...
...
Upvotes: 4
Views: 488
Reputation: 8865
Use 3 querys and join the results together by using union
(select * from sph where value = 0)
union
(select * from sph where value < 0 order by value desc)
union
(select * from sph where value > 0 order by value asc)
Upvotes: 1
Reputation: 72185
Try this:
ORDER BY CASE
WHEN Value = 0 THEN 0
WHEN Value < 0 THEN 1
ELSE 2
END ASC,
ABS(Value) ASC
The first part of the ORDER BY
places 0
value first, followed by negative values, followed by positive values. The second part orders negative values in descending order and positive values in ascending order.
Upvotes: 5