我有一个包含地址的表。我想执行一个查询来选择数值匹配的行。
address1 postcode
13 Some Road SW1 1AA
House 5 G3 7L
例如
select * from addresses where numeric(address1)=13 and numeric(postcode)=11
^^这将匹配第一排
select * from addresses where numeric(address1)=5 and numeric(postcode)=37
^^这将与第二排相匹配
这可能吗?
是的,这是可能的。您可以编写一个函数,该函数使用正则表达式将字段中的所有非数字字符替换为空字符,这样结果将仅为该函数返回的数字字符,然后对该函数进行筛选。
你可能对这个stackoverflow问题和这篇博客文章感兴趣。
另请参阅mysql-udf regexp。
select * from addresses where address1 REGEXP '(13)' and postcode REGEXP '(11)';