表字段stu为enum('1','0','-1','-2')并对其建立了索引,要查找所有非stu字段为非0的信息,以下几种方法哪一种比较的快的
1. where stu!='0'
2. where stu='1' or stu='-1' or stu='-2'
3. where stu IN('1','-1','-2')
1. where stu!='0'
2. where stu='1' or stu='-1' or stu='-2'
3. where stu IN('1','-1','-2')
如果是varchar类型的,3种情况都用不上索引的如果是int类型的话,则后面2种情况都可以利用上索引当然利用上索引的比没利用上索引的要快啦
你首先要确定你的stu字段的内容值为什么类型,如('1','0','-1','-2')还是(1,0,-1,-2)
若是1,0,-1,-2则后面2种写法可以用上索引
你自己用explain跟踪下看看吧