随笔 - 148  文章 - 3  评论 - 2  阅读 - 11万

存储过程--InOut

1. 存储过程名称:p_t_tradinglist

2. 参数 

 

3. 过程:

   

复制代码
BEGIN

  #Routine body goes here...
  set @row=0;

  select 
   @row:=@row+1 as '序号',
   DATE_FORMAT(a.llcurtime,'%Y-%m-%d %T') as '成交时间', if (b.exchange='SHFE','上期所', 
   if(b.exchange='DCE', '大商所', if(b.exchange='CZCE', '郑商所', 'XXX'))) as '交易所',
    b.goodname as '商品', a.contractid as '合约', if(a.direct='50','', if(a.direct='51','','XXX')) as '买/卖',
    a.price as '成交价', sum(a.share) as '手数',
   if(a.flag=48,'开仓',(if(a.flag='51','平今', if(a.flag='52','平昨','XXX')))) as '开/平', -a.commission as '手续费',
    a.orderid, d.price1 as '开仓价', a.price as '平仓价', c.lastPrices  as '结算价', e.vol_muliple,a.flag,   
   if(a.flag='48','', if(a.flag='51',(sum(a.share*a.price)/sum(a.share)-d.price1),(sum(a.share*a.price)/sum(a.share)-c.lastPrices))*if(direct='50',-1,1)*a.share*e.vol_muliple) as '平仓盈亏'
   #,a.innerorderid
   from hd_position_operator a 
     left JOIN hdmarket_monitor.t_good_instrument b on a.contractid = b.instrumentid 
     left join (select open_day, last_day from hd_trading_date)f on f.open_day = a.lltradedate
     LEFT JOIN (select open_day, instrument, lastPrices from hd_settle_price)c 
            on b.instrumentid = c.instrument and c.open_day = f.last_day
     LEFT JOIN (select orderid, sum(price*share)/sum(share) as price1 from hd_position_operator where flag = '48' and errorcode = '64'
                group by orderid)d on a.orderid = d.orderid
     left join (select contractid, vol_muliple from hd_contract_parm group by contractid)e on a.contractid = e.contractid
   where a.serid like i_serid and a.lltradedate = i_tradingdate and a.errorcode = '64' group by a.innerorderid 
   order by a.llcurtime; 

END
复制代码

 

4. 执行过程:

   call p_t_tradinglist('%110112%','20180530')

 

posted on   bruce_he  阅读(355)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示