mysql将字符串转为数字的方法:
- 1、利用“+”运算符,语法“'字符串' + 0”;
SELECT JSON_EXTRACT(charge_sts,'$.waiter') k1,JSON_EXTRACT(charge_sts,'$.waiter')+0 k2,'0121' k3,'012'+0 k4 from test
- 2、利用cast()函数,语法“cast('字符串' as 数值类型)”;
SELECT JSON_EXTRACT(charge_sts,'$.waiter') k1,CAST(JSON_EXTRACT(charge_sts,'$.waiter') AS SIGNED) k2,'0121' k3,CAST('012' AS SIGNED) k4 from mo_loan_order_charge HAVING k2=0;
- 3、利用convert()函数,语法“convert('字符串', 数值类型)”。
SELECT JSON_EXTRACT(charge_sts,'$.waiter') k1,CONVERT(JSON_EXTRACT(charge_sts,'$.waiter'),SIGNED) k2,'0121' k3,CONVERT('012',SIGNED) k4 from mo_loan_order_charge HAVING k2=0;
备注:数值类型(三种):
- 整数: SIGNED
- 无符号整数: UNSIGNED
- 浮点数: DECIMAL