Suggestions for Optimizing this Query

  • update researchdaily set spfac1 = b.spfac from researchdaily join

                (SELECT * FROM

                (

                            SELECT DISTINCT BD.td AS BusinessDate,

                            (SELECT MAX(PriorBD.td)

                            FROM   (SELECT DISTINCT td FROM researchdaily) AS priorBD

                            WHERE  PriorBD.td < BD.td) 

                            AS PriorDate

                            FROM

                            (SELECT DISTINCT td FROM researchdaily) As BD

                            group by BD.td 

                ) as dates

                where PriorDate is not null

                ) as a

    on researchdaily.td = a.priordate join

    (select td, cusip, spfac from researchdaily) as b on a.businessdate = b.td and researchdaily.cusip = b.cusip

     


    jcollins

  • Wow, not sure you need all the subqueries. Try converting some of those to joins.

    like

    update researchdaily set spfac1 = b.spfac from researchdaily

    join (...) a

    inner join researchdaily b

    on a.businessdate = b.td

    and researchdaily.cusip = b.cusip

  • Hi ,

    Can u specify ur requirement.. so that i can simplyfy ur query.

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply