存储过程——mysql

CALL pr_build_kline_day ('t_quote_quote_NYMEX', 't_quote_kline_day_NYMEX');


drop procedure if exists pr_build_kline_min;

create procedure pr_build_kline_min
(
  in in_quote_table varchar(1024),
  in in_kline_table varchar(1024)
)
lablel:begin


#min,max
SET @sqlcmd = CONCAT('INSERT into ',in_kline_table,'(instrumentid, quotetime, lowestprice, highestprice) 
select instrumentid, substr(updatetime, 1, 16) as newtime, MIN(lastprice) as low, MAX(lastprice) as high 
from ',in_quote_table,' GROUP BY instrumentid, substr(updatetime, 1, 16)');
PREPARE temp FROM @sqlcmd;
EXECUTE temp;
DEALLOCATE PREPARE temp;


#open
SET @sqlcmd = CONCAT('UPDATE ',in_kline_table,' a INNER JOIN 
(select instrumentid, substr(updatetime, 1, 16) as newtime, lastprice from ',in_quote_table,'
where id in (select distinct min(id) as id from ',in_quote_table,' group by instrumentid, substr(updatetime, 1, 16))
) b 
on a.instrumentid = b.instrumentid and a.quotetime = b.newtime
set a.openprice = b.lastprice');
PREPARE temp FROM @sqlcmd;
EXECUTE temp;
DEALLOCATE PREPARE temp;


#close
SET @sqlcmd = CONCAT('UPDATE ',in_kline_table,' a INNER JOIN 
(select instrumentid, substr(updatetime, 1, 16) as newtime, lastprice from ',in_quote_table,'
where id in (select distinct max(id) as id from ',in_quote_table,' group by instrumentid, substr(updatetime, 1, 16))
) b 
on a.instrumentid = b.instrumentid and a.quotetime = b.newtime
set a.closeprice = b.lastprice');
PREPARE temp FROM @sqlcmd;
EXECUTE temp;
DEALLOCATE PREPARE temp;


#quotetime
SET @sqlcmd = CONCAT('UPDATE ',in_kline_table,' set quotetime = concat(quotetime, ":00")');
PREPARE temp FROM @sqlcmd;
EXECUTE temp;
DEALLOCATE PREPARE temp;


end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值