浏览 2606 次
锁定老帖子 主题:本人菜鸟,求大神给优化个sql
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2015-08-10
SELECT t.id as id, t.tm_projectinfo_id as tmProjectinfoId, t.node_name as nodeName, t.report_name as reportName, t.report_path as reportPath, t.node_date as nodeDate, t.create_user as createUser, t.create_datetime as createDatetime, t.update_user as updateUser, t.update_datetime as updateDatetime, t.remark as remark, t.delete_flag as deleteFlagD FROM TT_KEYNOTE_REPORT t, tm_projectinfo pro where t.tm_projectinfo_id = pro.id and pro.project_cn = 'Fabia NF (SK260 CS)' and t.delete_flag = '0' and pro.delete_flag = '0' and t.create_datetime = (select max(kr.create_datetime) from tt_keynote_report kr, tm_projectinfo pro1 where kr.tm_projectinfo_id = pro1.id and pro1.project_cn = 'Fabia NF (SK260 CS)' and kr.delete_flag = '0' and pro1.delete_flag = '0' group by kr.tm_projectinfo_id) order by t.node_name ; 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2015-08-16
SELECT t.id as id,
t.tm_projectinfo_id as tmProjectinfoId, t.node_name as nodeName, t.report_name as reportName, t.report_path as reportPath, t.node_date as nodeDate, t.create_user as createUser, t.create_datetime as createDatetime, t.update_user as updateUser, t.update_datetime as updateDatetime, t.remark as remark, t.delete_flag as deleteFlagD , max(t.create_datetime) md FROM TT_KEYNOTE_REPORT t, tm_projectinfo pro where t.tm_projectinfo_id = pro.id and pro.project_cn = 'Fabia NF (SK260 CS)' and t.delete_flag = '0' and pro.delete_flag = '0' having t.create_datetime = md order by t.node_name ; |
|
返回顶楼 | |
发表时间:2015-09-06
这样效率可能更快点,Oracle的执行顺序是自下而上,尽量把能过滤多数据的条件放在最后。
select t.id as id, t.tm_projectinfo_id as tmprojectinfoid, t.node_name as nodename, t.report_name as reportname, t.report_path as reportpath, t.node_date as nodedate, t.create_user as createuser, t.create_datetime as createdatetime, t.update_user as updateuser, t.update_datetime as updatedatetime, t.remark as remark, t.delete_flag as deleteflagd, max(t.create_datetime) md from tt_keynote_report t, tm_projectinfo pro where t.tm_projectinfo_id = pro.id and t.delete_flag = '0' and pro.delete_flag = '0' and pro.project_cn = 'Fabia NF (SK260 CS)' having t.create_datetime = md order by t.node_name; |
|
返回顶楼 | |