Mysql conversion method to int: 1. Convert the type manually; 2. Use the MySQL function CAST to achieve conversion; 3. Use the MySQL function CONVERT to achieve the conversion.
Recommended: "PHP Video Tutorial"
MySQL varchar to int
1. Manual conversion type (direct 0)
Example:
select server_id from cardserver where game_id = 1 order by server_id+0 desclimit 10
2. Use MySQL function CAST:
Example:
select server_id from cardserver where game_id = 1 order by CAST(server_id as SIGNED) desc limit 10;
3. Use MySQL function CONVERT:
Example:
select server_id from cardserver where game_id = 1 order by CONVERT(server_id,SIGNED)desc limit 10;
Note:
CAST function, CONVERT usage
CAST(expr AS type), CONVERT( expr,type) , CONVERT(expr USING transcoding_name)
CAST() and CONVERT() functions can be used to obtain a value of one type and produce a value of another type.
This type can be one of the following values:
BINARY[(N)] CHAR[(N)] DATE DATETIME DECIMAL SIGNED [INTEGER] TIME UNSIGNED [INTEGER]
The above is the detailed content of How to convert mysql to int. For more information, please follow other related articles on the PHP Chinese website!