Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要比较存储在 varchar 字段中的数字,例如我有一个表:
id | values 1 | 2 2| 154 3 | 88 4 | 35
我需要查找大于 5 的数字,如果我可以对values字段使用 int 属性,一切都会好起来的,但我必须使用 varchar。有没有简单的解决方案?
values
你需要使用
CAST(`values` AS UNSIGNED)
像那样
select * from table WHERE CAST(`values` AS UNSIGNED) > 5
演示
编辑:
假设你用负号签署了数字-
-
然后
select * from table1 WHERE CAST(`values` AS SIGNED) > 5