【发布时间】:2013-07-21 23:10:45
【问题描述】:
Loop1 是通过一些简单的逻辑得出的。 Loop2 是通过非常复杂的逻辑导出的。 Loop3 很简单,就是在 Loop2 上加 2 得到
现在,我想通过 Loop1、Loop2 和 Loop3 的组合推导出 Loop4。问题是 loop2 是一个非常繁重的逻辑,如果我在 Loop3 中再次导出逻辑,查询运行速度非常慢。为了更清楚,我发现 loop3 使用 loop1&2 和 loop4 使用 loop1,2&3。请提出一种方法来使这个查询工作。
select sre.shipmentId,
loop1.TRY1,
loop2.TRY2,
loop3.TRY3,
(select case when u>0 then loop1.TRY1 when u>1 then loop2.TRY2 else loop3.TRY3 end) as loop4
from `shipmentRouteEvent` sre
left join (select sre1.shipmentId as s1, (case when .....>0 then .... end) ad TRY1
from `shipmentRouteEvent` sre1
where sre1.updateDate='2013-07-01'
) as loop1 on sre.id=try1.id
left join (select some heavy logic which will modify TRY1 to TRY2) as loop2
left join (select (TRY2+2) as TRY3) as loop3
where sre.updateDate='2013-07-01'
【问题讨论】:
-
非常怀疑您是否需要这么多左连接(如果有的话)来完成这个逻辑。您能否提供有关确定
TRY的算法以及确定TRY2的“重逻辑”的更多详细信息?
标签: mysql sql loops subquery correlated-subquery