mysql - Multiple interrelated loops in sql -
loop1 derived through easy logic. loop2 derived through complex logic. loop3 simple derived adding 2 loop2
now, want derive loop4 through combination of loop1, loop2 & loop3. problem loop2 heavy logic , query running slow if derive logic again inside loop3. provide more clarity, finding loop3 using loop1&2 , loop4 using loop1,2&3. please suggest way query work.
select sre.shipmentid, loop1.try1, loop2.try2, loop3.try3, (select case when u>0 loop1.try1 when u>1 loop2.try2 else loop3.try3 end) loop4 `shipmentrouteevent` sre left join (select sre1.shipmentid s1, (case when .....>0 .... end) ad try1 `shipmentrouteevent` sre1 sre1.updatedate='2013-07-01' ) loop1 on sre.id=try1.id left join (select heavy logic modify try1 try2) loop2 left join (select (try2+2) try3) loop3 sre.updatedate='2013-07-01'
i think want nested subqueries:
from (select . . . fro (select . . . `shipmentrouteevent` sre left join (select sre1.shipmentid s1, (case when .....>0 .... end) ad try1 `shipmentrouteevent` sre1 sre1.updatedate='2013-07-01' ) loop1 on sre.id=try1.id ) loop1 left join (select heavy logic modify try1 try2 ) loop2 on . . . ) loop2 left outer join (. . . ) loop3 on . . .
each level of nesting allow use results @ next level, results not need recalculated.
Comments
Post a Comment