我有一列称为value
,其中包括字符串以及数字和数据,例如:
我需要一种方法来仅检索实际数字(以及<= 180
)的结果。
从上面的预期结果应该是:18, 150
和16, 50
,但我用绳子得到的结果也是如此。
我已经从其他SO问题尝试过此方法:
SELECT *
FROM `contentvalues`
WHERE (
contentid =16
OR contentid =18
)
AND `value` <= 180
AND value NOT LIKE '%[a-z0-9]%'
但这没有用。
有人能指出我正确的方向吗?
根据此:
... AND value REGEXP ('[0-9]')
...但是某人的博客绝不是最佳来源。实际上,它匹配包含数字的所有内容。更好的是
... AND value REGEXP ('^[0-9]+$')
正则表达式上方是
^ "From the begining of the string..."
[0-9] "There should be a number..."
+ "actually exactly 1 or more of those numbers"
$ "and the the string should just end."
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句