mysql里面如何用sql语句让字符串的‘123’转换为数字的123?
方法一:SELECT CAST("123" AS SIGNED integer);
方法二:SELECT CONVERT("123",SIGNED);
方法三:SELECT "123"+0;
同样,当需要将一列字符串转换为数字也可以使用此方法,或者需要用到字符串进行排序的时候可以使用到此方法:
SELECT * FROM answer WHERE question_id = xx ORDER BY CONVERT(`code`,SIGNED)
SELECT * FROM answer WHERE question_id = xx ORDER BY cast(`code` as signed integer)