Converting sql query WITH clause query to mysql query -


i converting sql queries mysql queries, queries have clauses failing.

here query:

with cte (     select sto.ndate ndate,sto.nstockname stkname,sto.nclosingprice stkclosingprice, sto.nvolume stkvolume,      ind.nstockname indname,ind.nclosingprice indclosingprice, ind.nvolume indvolume,     rownum = row_number() on (partition sto.nstockname order sto.ndate)     equitystockoptions_nse sto         join equitystockoptions_indices ind on sto.ndate = ind.ndate     ind.nstockname='nifty' , str_to_date(date_format(sto.ndate,'%m/%d/%y')) >= date_format(v_fromdate,'%m/%d/%y') , str_to_date(date_format(sto.ndate,'%m/%d/%y')) <= date_format(v_todate,'%m/%d/%y') ) select curr.ndate,curr.stkname,curr.stkclosingprice, curr.stkvolume, curr.indname, curr.indclosingprice, curr.indvolume,  log(curr.stkclosingprice / prev.stkclosingprice) stkreturnonlog, log(curr.indclosingprice / prev.indclosingprice) indreturnonlog cte curr inner join cte prev on prev.rownum = curr.rownum - 1 , curr.stkname = prev.stkname order stkname, ndate; 

any suggestion on conversion appreciated.

with lets assign name inline view (a subquery used in clause). know mysql doesn't support with, can replace "cte" references actual subquery:

select  curr.ndate,curr.stkname,curr.stkclosingprice, curr.stkvolume,          curr.indname, curr.indclosingprice, curr.indvolume,         log(curr.stkclosingprice / prev.stkclosingprice) stkreturnonlog,          log(curr.indclosingprice / prev.indclosingprice) indreturnonlog (     select sto.ndate ndate,sto.nstockname stkname,sto.nclosingprice stkclosingprice, sto.nvolume stkvolume,      ind.nstockname indname,ind.nclosingprice indclosingprice, ind.nvolume indvolume,     rownum = row_number() on (partition sto.nstockname order sto.ndate)     equitystockoptions_nse sto         join equitystockoptions_indices ind on sto.ndate = ind.ndate     ind.nstockname='nifty' , str_to_date(date_format(sto.ndate,'%m/%d/%y')) >= date_format(v_fromdate,'%m/%d/%y') , str_to_date(date_format(sto.ndate,'%m/%d/%y')) <= date_format(v_todate,'%m/%d/%y') ) curr inner join (     select sto.ndate ndate,sto.nstockname stkname,sto.nclosingprice stkclosingprice, sto.nvolume stkvolume,      ind.nstockname indname,ind.nclosingprice indclosingprice, ind.nvolume indvolume,     rownum = row_number() on (partition sto.nstockname order sto.ndate)     equitystockoptions_nse sto         join equitystockoptions_indices ind on sto.ndate = ind.ndate     ind.nstockname='nifty' , str_to_date(date_format(sto.ndate,'%m/%d/%y')) >= date_format(v_fromdate,'%m/%d/%y') , str_to_date(date_format(sto.ndate,'%m/%d/%y')) <= date_format(v_todate,'%m/%d/%y') ) prev on prev.rownum = curr.rownum - 1 , curr.stkname = prev.stkname order stkname, ndate; 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -