2017-11-29 16 views
1
import datetime 
from datetime import date 

Start_Date = date(2010, 01, 01) 
market = 1 
Query_PNL = """SELECT rptday,extract(year from rptday),extract(month from rptday),a.botid,closetoclosepnl, 
       case when closetoclosepnl > 0 then 1 
        when closetoclosepnl < 0 then 0 
       END AS PNL_score 
       FROM RESEARCH.ADMIN.BOTSDAILYPNL a 
        --order by botid desc, rptday asc; 
      right join 

       (SELECT marketid,botid,modelid 
       FROM RESEARCH.ADMIN.BOTS 
       where modelid = 2018 and botname like '%BackTesting')b 
       on a.MARKETID = b.marketid and a.BOTID = b.botid 
       where a.rptday >='2010-01-01' and a.rptday <='2010-01-31' and a.MARKETID = %s and PNL_score is not null 
       order by rptday asc""" %(market) 
print Query_PNL 
+0

おそらく '%BackTesting'の「%」のために... – alfasin

+0

@alfasin:それは真実かもしれません、ただ実現しました。私は、クエリを再配置しようとし、再度実行されます。ありがとう –

答えて

1

を形成しながら、私は次のコードを実行しようとすると、(それを2倍にすることにより)likeオペレータで使用している%文字をエスケープする必要があるので、Pythonはそれを評価しようとしませんスロー:

Query_PNL = """SELECT rptday,extract(year from rptday),extract(month from rptday),a.botid,closetoclosepnl, 
       case when closetoclosepnl > 0 then 1 
        when closetoclosepnl < 0 then 0 
       END AS PNL_score 
       FROM RESEARCH.ADMIN.BOTSDAILYPNL a 
        --order by botid desc, rptday asc; 
      right join 

       (SELECT marketid,botid,modelid 
       FROM RESEARCH.ADMIN.BOTS 
       where modelid = 2018 and botname like '%%BackTesting') 
       on a.MARKETID = b.marketid and a.BOTID = b.botid 
       where a.rptday >='2010-01-01' and a.rptday <='2010-01-31' and a.MARKETID = %s and PNL_score is not null 
       order by rptday asc""" %(market) 
+0

それは働いた。どうもありがとうございました –