select id from table where num is null
解决方法:建表时设置默认值0,也就是将null用0填充,然后查询:
select id from table where num=0
select id from t where num=10 or num=20
解决方法:使用 union
select id from t where num=10 union all select id from t where num=20
select id from t where name like ‘%abc%’
解决方法:使用全文检索
select id from t where num in(1,2,3)
解决方法1:连续值使用 between
解决方法2:用 exists 替换 in
select num from a where exists(select 1 from b where num=a.num)
select id from t where num=@num
解决方法:强制查询使用索引
select id from t with(index(index_name)) where num=@num
select id from t where num/2=100
解决方法:select id from t where num=100*2
select id from t where substring(name,1,3)=’abc’
查询以abc开头的id
解决方法:全文索引