In the operation of MySQL, often need to convert characters into numbers, this step is simple, but not commonly used words are easy to forget, now will be found on the Internet The method is recorded as follows:
1. Convert the number of characters to a number, such as ' 0 ' to 0 can be directly implemented with addition
For example: Sorting d in the Pony table can be defined as varchar, which can be resolved
SELECT * FROM Pony ORDER by (d+0)
2. In the case of ifnull processing, such as ifnull (A/b, ' 0 ') This causes A/b to become a string, so we need to change the ' 0 ' to 0 to solve this problem.
3. Compare numbers and varchar, such as a=11,b= "11DDDDD";
The Select 11= "11ddddd" is equal
If the absolute comparison can be this:
Select binary one =binary "11DDDDD"
4. Character Set conversion: convert (XXX USING gb2312)
Type conversions are just like SQL Server, where type parameters are a little different: CAST (xxx as type), convert (XXX, type), type must be of the following types:
Available types:
Binary, with binary prefix effect: binary
Character type, with parameters: CHAR ()
Date: Date
Time:
DateTime Date/Time type
Floating point number: DECIMAL
Integer: Signed
unsigned integer: UNSIGNED
http://blog.csdn.net/dengsilinming/article/details/8481417
MySQL converts characters into numbers