数据库查询优化
来源:互联网 发布:云网络 编辑:程序博客网 时间:2024/06/06 00:25
数据库查询优化,尽量使用JOIN,代替子查询
原来的SQL:SELECT bu.realname,bu.username,de.departname from t_s_base_user bu
LEFT JOIN t_s_user_org uo on uo.user_id=bu.ID
left JOIN t_s_depart de on de.ID= uo.org_id
WHERE not exists (select r.responsibleid from t_family_info fi
LEFT JOIN t_responsible r on r.infoid=fi.id
WHERE fi.id in (select f.infoid from t_follow f where f.addtime>='2016-09-01') and r.responsibleid=bu.ID)
and bu.ID in (select responsibleid from t_responsible)
优化后的SQL:
select * from (SELECT bu.ID,bu.realname,bu.username,de.departname from t_s_base_user bu
LEFT JOIN t_s_user_org uo on uo.user_id=bu.ID
left JOIN t_s_depart de on de.ID= uo.org_id
INNER join t_responsible r ON r.responsibleid=bu.id GROUP BY bu.ID) as temp
LEFT JOIN (select r.responsibleid from t_family_info fi
LEFT JOIN t_responsible r on r.infoid=fi.id
WHERE fi.id in (select f.infoid from t_follow f where f.addtime>='2016-09-01')) as temp2 ON
temp.ID=temp2.responsibleid WHERE temp2.responsibleid IS NULL
- 数据库优化:优化查询
- 数据库优化--优化查询语句
- 数据库查询优化技术
- MYSQL数据库查询优化
- 数据库查询优化
- 数据库查询优化
- 数据库 查询优化
- 优化MySQL数据库查询
- 数据库查询性能优化
- 优化MySQL数据库查询
- 优化MySQL数据库查询
- 数据库查询优化
- 数据库查询优化(上)
- 数据库查询优化(下)
- 数据库查询优化
- 数据库查询优化
- 优化MySQL数据库查询
- 优化数据库查询
- 如何正确配置Nginx+PHP
- Maven知识点记录 - profile
- 用js实现倒计时和在页面显示当前时间
- app缓存策略
- JavaScript数组去重的几种方法
- 数据库查询优化
- Android设计模式--推荐使用的两种单例模式
- 各编程语言中 Base64 编码解码的方法
- postgres 修改视图
- jaxb2.1的使用示例
- java类实现serializable有什么好处或意义
- Maven知识- repositories
- AnnotationSessionFactoryBean与LocalSessionFactoryBean的区别
- 查看火狐浏览器的参数配置