Mysql Query statement problem, urgent request, thank you Table a, there are fields a_sort (int), a_date (bigint), respectively for sorting and date, date storage timestamp
A_sort a_date
0 1403172542
0 1403056816
0 1403172558
1 1403172594
2 1403056323
4 1403056888
6 1402655021
5 1403056634
The query results are displayed in ascending order of a_sort, but 0 is not involved in ascending order, followed by descending order of date.
I wrote
Select * from a order by a_sort> 0 asc, a_date desc,
Or
Select * from a order by a_sort! = 0 asc, a_date desc
None
How can I write this statement ??
Reply to discussion (solution)
Select * from a order by a_sort = 0, a_sort, a_date desc
Try it ~
0 No ?? What is ascending order? Meaning?
In the ascending order of a_sort, 0 is the first. what you want is non-zero first in ascending order, 0 is the last, and then the whole? Then press ?? In reverse order?
SELECT * FROM 'A' order by a_sort> 0 desc, a_sort asc, a_date desc;
0 No ?? What is ascending order? Meaning?
In the ascending order of a_sort, 0 is the first. what you want is non-zero first in ascending order, 0 is the last, and then the whole? Then press ?? In reverse order?
SELECT * FROM 'A' order by a_sort> 0 desc, a_sort asc, a_date desc;
0 No ?? What is ascending order? Meaning?
The result I want is to first display the non-zero a_sort and sorted by asc for non-zero. The rest is the zero a_sort, which is displayed in descending order of date.
... Order by a_sort> 0 desc, a_sort, a_date desc
a_sort a_date 1 1403172594 2 1403056323 4 1403056888 5 1403056634 6 1402655021 0 1403172558 0 1403172542 0 1403056816
Is there anything wrong with this?
Select * from a order by if (a_sort! = 0, 0) desc, a_sort asc, a_date desc
You can do it on the 2nd floor. thank you for solving the problem. you can do it on the 1st floor, or on the 5th floor. thank you very much.