我有varchar列类型。这是列值的示例-"A - 474, B - 709, C - 397, D - 48"
如果我想搜索EXACT号,一切都很好。我使用php和查询-

$note[$key][0] = "B";
$note[$key][1] = "709";

"SELECT 1 FROM example WHERE column LIKE '%".$note[$key][0]." - ".$note[$key][1]."%"


但是,如何修改查询以搜索增加的值?
我想要这样的东西:

"SELECT 1 FROM example WHERE column LIKE '%".$note[$key][0]." and value >= 50"%"


我认为RLIKE可能是解决方案。那正确吗?是否存在性能问题?

最佳答案

您可以拆分值。我会说substring_index()是必经之路:

where column = '$key[0]%' and
      substring_index(column, ' - ', -1) + 0 >= 50


注意:您应该开始使用参数化查询,而不是将用户提供的值嵌入查询字符串中。

关于php - 如果列值具有自定义模板,如何在MySQL中搜索递增值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32684634/

10-14 18:00
查看更多