Sorting of mysql string fields

Source: Internet
Author: User
For sorting of mysql string fields, I have A varchar type field. There are three pieces of data in the order by a desc, the order is as follows: 2013.03, 2013.02, 2013.04
How can I keep the latest time at the top? Without modifying the field type of a data table.


Reply to discussion (solution)

Assume that the 2013.03 field is shijian.
Order by a desc, shijian desc

Order by can have multiple fields

Assume that the 2013.03 field is shijian.
Order by a desc, shijian desc

Order by can have multiple fields

The key is that the 2013.03 field is.



I tried it in the following order according to your requirements... I don't know why you can't get the same result...



I tried it in the following order according to your requirements... I don't know why you can't get the same result...

Is your field type varchar?



Yes varchar



I tried it in the following order according to your requirements... I don't know why you can't get the same result...

When you say this, I will go back and look at it again. Ah, I found that the data is sorted again normally. I don't even know why. It's too bad.

For the sake of insurance, I finally split it into two fields. One is used to save the year, and the other is used to save the month, which is an integer. Ranking is more reliable.
I still don't understand. the sorting is not normal today. I have been thinking about it for a long time and it will be normal again in the evening. Evil.

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.