MySQL中int类型的字段使用like查询方法

方法参考自:

http://stackoverflow.com/questions/8422455/performing-a-like-comparison-on-an-int-field

也就是使用CAST转换指定字段,然后进行比较。具体样例代码如下:

SELECT ProductID, ProductName FROM Products WHERE CAST(ProductID as CHAR) LIKE '%15%'

 

但是这样做的话,MySQL不能使用对应int字段索引,而且like本身就很慢。

 

建立一个多余字段varchar类型对应int类型,会更有效一些。

 
posted @ 2016-12-30 09:30  冰岛  阅读(6433)  评论(0编辑  收藏  举报