我有两个临时表,我正在从存储过程中提取数据
#rtn
好像
dt indx_nm cusip_id lrtn
2013-08-19 00:00:00.000 ABQI 33736Q104 -10.2
2013-08-16 00:00:00.000 ABQI 33736Q104 2.28
2013-08-15 00:00:00.000 ABQI 33736Q104 -18.38
2013-08-14 00:00:00.000 ABQI 33736Q104 -2.73
2013-08-13 00:00:00.000 ABQI 33736Q104 3.38
2013-08-12 00:00:00.000 ABQI 33736Q104 2.45
2013-08-19 00:00:00.000 ACNACTR 18385P101 -0.13
2013-08-16 00:00:00.000 ACNACTR 18385P101 -0.02
2013-08-15 00:00:00.000 ACNACTR 18385P101 -0.51
2013-08-14 00:00:00.000 ACNACTR 18385P101 -0.37
2013-08-13 00:00:00.000 ACNACTR 18385P101 5.2
2013-08-12 00:00:00.000 ACNACTR 18385P101 6.31
等等更多的不同indx_nm
和cusip_id
#rtn2
好像
dt cusip_id lrtn
2013-08-19 00:00:00.000 00162Q106 -0.00752860307693481
2013-08-16 00:00:00.000 00162Q106 -0.0131599903106689
2013-08-15 00:00:00.000 00162Q106 -0.0369237661361694
2013-08-14 00:00:00.000 00162Q106 -0.0315451622009277
2013-08-13 00:00:00.000 00162Q106 -0.0180829167366028
2013-08-12 00:00:00.000 00162Q106 -0.0140992403030396
2013-08-19 00:00:00.000 00162Q205 -0.00420033931732178
2013-08-16 00:00:00.000 00162Q205 -0.00409352779388428
2013-08-15 00:00:00.000 00162Q205 -0.023819625377655
2013-08-14 00:00:00.000 00162Q205 -0.0221214294433594
2013-08-13 00:00:00.000 00162Q205 -0.0169548392295837
2013-08-12 00:00:00.000 00162Q205 -0.00570738315582275
还有很多不同的indx_nm
地方cusip_id
我当前的代码是:
insert into etf_table (indx_nm, cusip_id, cor, dt_pnts)
select a.indx_nm, b.cusip_id,
(AVG(a.lrtn * b.lrtn) - AVG(a.lrtn)*AVG(b.lrtn))/ STDEVP(a.lrtn)/STDEVP(b.lrtn) cor, COUNT(*) dt_pnts
from #rtn a, #rtn2 b
where a.dt = b.dt and a.lrtn is not null and b.lrtn is not null
group by a.indx_nm, b.cusip_id
having STDEVP(a.lrtn) > 0 and STDEVP(b.lrtn) > 0
order by a.indx_nm, cor desc
但是,我只想(AVG(a.lrtn * b.lrtn) - AVG(a.lrtn)*AVG(b.lrtn))/ STDEVP(a.lrtn)/STDEVP(b.lrtn)
按照名为的表运行etf_data
Ticker CUSIP_ID Indx
AADR 00768Y206 MXEA
AAIT 46429B374 MSIAITNU
AAXJ 464288182 NDUECAXJ
ABCS 18383Q788 BKABCT
(更多ticker
,cusip_id
而且indx
很明显)
条件是:in
indx_nm
匹配#rtn
此Indx
表中的 in,其中in
# cusip_id
rtn2cusip_id
沿每一行匹配此表中
的(AVG(a.lrtn * b.lrtn) - AVG(a.lrtn)*AVG(b.lrtn))/ STDEVP(a.lrtn)/STDEVP(b.lrtn)
cusip_id
00768Y206
indx
MXEA
cusip_id
indx
etf_data