MySQL varchar cannot use the max () function solution _ MySQL

Source: Internet
Author: User
In MySQL, varchar cannot use the max () function. Today, a problem occurs. in MySQL, data of the varchar type cannot use the max () function, which is not familiar with MySQL, so I checked and found that these two methods are good.

1. add 0 to the field that requires the max () function. for example, if field is a field that requires the max () function

Select max (field + 0) FROM tablename

This is the case. This should be done by MySQL itself, not very clear ~

2. Similarly, use the cast () function.

Select max (cast (field as decimal) FROM tablename
Here I convert it to the currency type, so max works.

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.