请教大神如何优化这段SQL,谢谢

熊德华 2018-07-11 05:42:02
select a.*,c.name Contract_TypeName,d.ecc_orga_name UnitName,d.ecc_orga_name VehicleTeamName
,e.name SettlementName,f.Vehicle_Number VehicleNo,g.Vehicle_Number TrailerNo
,case when a.Contract_Status=10 then '初始创建'when a.Contract_Status=20 then '合同作废'
when a.Contract_Status=30 then '审核完毕' end StatusName
,case when a.Old_Contract_KeyId is null
and a.Contract_Status = 30
and not exists(select * from Contract_Income_Contract where Old_Contract_KeyId = a.keyid and Is_Delete=0) then 1 else 0 end IsDifferAdjust

from Contract_InCome_Contract a
left join Dic_Contract_Type c on a.Dic_Contract_Type=c.keyid
left join Dic_Organization d on a.PartyA=d.keyid
left join Dic_Customer_Trans e on a.PartyB=e.keyid
left join Device_Vehicle f on a.fk_vehicle=f.keyid
left join Device_Vehicle g on a.fk_trailer=g.keyid
where a.keyid is not null

红色部分明显影响了查询速度,有更好的优化方法吗
...全文
190 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
碧水幽幽泉 2018-07-12
  • 打赏
  • 举报
回复
子查询换成表连接,再试试

select a.*,c.name Contract_TypeName,d.ecc_orga_name UnitName,d.ecc_orga_name VehicleTeamName
,e.name SettlementName,f.Vehicle_Number VehicleNo,g.Vehicle_Number TrailerNo
,case when a.Contract_Status=10 then '初始创建'when a.Contract_Status=20 then '合同作废'
when a.Contract_Status=30 then '审核完毕' end StatusName
case when a.Old_Contract_KeyId is null and a.Contract_Status = 30 and h.Old_Contract_KeyId is null then 1 else 0 end IsDifferAdjust
from Contract_InCome_Contract a
left join Dic_Contract_Type c on a.Dic_Contract_Type=c.keyid
left join Dic_Organization d on a.PartyA=d.keyid
left join Dic_Customer_Trans e on a.PartyB=e.keyid
left join Device_Vehicle f on a.fk_vehicle=f.keyid
left join Device_Vehicle g on a.fk_trailer=g.keyid
left join Contract_Income_Contract h on h.Old_Contract_KeyId = a.keyid and h.Is_Delete = 0
where a.keyid is not null
碧水幽幽泉 2018-07-12
  • 打赏
  • 举报
回复
子查询换成表连接,再试试

select a.*,c.name Contract_TypeName,d.ecc_orga_name UnitName,d.ecc_orga_name VehicleTeamName
,e.name SettlementName,f.Vehicle_Number VehicleNo,g.Vehicle_Number TrailerNo
,case when a.Contract_Status=10 then '初始创建'when a.Contract_Status=20 then '合同作废'
when a.Contract_Status=30 then '审核完毕' end StatusName
case when a.Old_Contract_KeyId is null and a.Contract_Status = 30 and h.Old_Contract_KeyId is null then 1 else 0 end IsDifferAdjust
from Contract_InCome_Contract a
left join Dic_Contract_Type c on a.Dic_Contract_Type=c.keyid
left join Dic_Organization d on a.PartyA=d.keyid
left join Dic_Customer_Trans e on a.PartyB=e.keyid
left join Device_Vehicle f on a.fk_vehicle=f.keyid
left join Device_Vehicle g on a.fk_trailer=g.keyid
left join Contract_Income_Contract h on h.Old_Contract_KeyId = a.keyid and h.Is_Delete = 0
where a.keyid is not null

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧