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类型,会更有效一些。

 
文章来自:http://www.cnblogs.com/yaoliang11/p/6235656.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3