Mysql Query statement problem, please, thank you

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.