Method: 1. Use "String 0" to convert, the syntax is "(column 0)"; 2. Use the CONVERT function to convert, the syntax is "CONVERT(column,SIGNED)"; 3. Use the CAST function Conversion, the syntax is "CAST(column as SIGNED)".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
1. Directly use addition
String 0
The example is as follows
example: select * from orders order by (column+0) desc
2. Use the CAST function
CAST(column as type);
The CAST() function converts any type of value to a value of the specified type. The target type can be one of the following types: BINARY, CHAR, DATE, DATETIME, TIME, DECIMAL, SIGNED, UNSIGNED.
2. Use the CONVERT function
CONVERT(column, type);
MySQL CONVERT() provides a method to convert data between different character sets.
Note:
The type here can be:
Floating point number: DECIMAL
Integer: SIGNED
Unsigned integer: UNSIGNED
example: select * from orders order by CONVERT(column,SIGNED) desc select * from orders order by CAST(column as SIGNED) desc
Recommended learning: mysql video tutorial
The above is the detailed content of How to convert string to integer in mysql. For more information, please follow other related articles on the PHP Chinese website!