1. 少用 in 和 not in: select id from t where num in(1,2,3) -> select id from t where num between 1 and 3 ;
2. 少用 or 来连接where子句: select id from t where num=10 or num=20 ->
select id from t where num=10
union all
select id from t where num=20
3. 避免where子句中用 null 筛选,用 默认值0 代替 null : select id from t where num is null -> select id from t where num=0 ;
4. 避免在where子句中对字段进行表达式操作: select id from t where num/2=100 -> select id from t where num=100*2 ;