提高查询效率的写法

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 筛选,用 默认值代替 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 ;

 

posted @ 2019-12-27 15:13  zhoushiya  阅读(146)  评论(0编辑  收藏  举报