MySQL's varchar fields are sorted by number

Source: Internet
Author: User

MySQL's varchar fields are sorted by number

Today, I encountered a question about sorting, when a table was built, and the wide fields in the table were stored with varchar, because the unit might be stored so it was not stored in Int. But later changed the need to say is not input units, at that time think of anyway can be used also there is no modification of the field type, reserved varchar.

Here's the point:

This is not sorted when the display

Now put it in ascending order

found that the problem of sorting, 1000 in front of 120, to solve this problem only need to convert the type on the line, the sort of field +0 can be converted

Sql:

Select rule from Th_steel order by rule+0 ASC;

You can also use the MySQL function to handle

MySQL's varchar fields are sorted by number

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.