添加到我的查询时,我无法获得以下行,任何想法? stddev(stat)偏见
with c as (
SELECT A.ENGINE_ASOF_CALENDAR_DATE, A.LEVEL_1_CODE CURR, CNTR_TO_ACTIVE_RISK, A.PRICE, a.ACTIVE_WEIGHT_PCT,
lag(a.PRICE, 1) over(partition by a.LEVEL_1_CODE order by a.ENGINE_ASOF_CALENDAR_DATE) price_lag,
lag(CNTR_TO_ACTIVE_RISK, 1) over(partition by a.LEVEL_1_CODE order by a.ENGINE_ASOF_CALENDAR_DATE) risk_lag,
price_lag/a.PRICE - 1 rtn,
a.ACTIVE_WEIGHT_PCT * rtn wgt_rtn
FROM DBS_APPL_RISK_DATAMART.USR_OWNR_RISK_DATAMART.VWC_FOREIGNEXCHANGE_FUND_EXPOSURE A
WHERE A.PORTFOLIO_CODE = 'Sunsuper Active - SUKHH3_Active'
)
SELECT c.*,
sum(wgt_rtn) over(partition by c.ENGINE_ASOF_CALENDAR_DATE)sum_rtn,
sum(risk_lag) over(partition by c.ENGINE_ASOF_CALENDAR_DATE)sum_risk_lag,
sum_risk_lag/sqrt(260) over(partition by c.ENGINE_ASOF_CALENDAR_DATE)sum_lag_risk2,
sum_rtn/nullif(sum_lag_risk2,0) stat,
stddev(stat) bias
FROM c
order by c.ENGINE_ASOF_CALENDAR_DATE desc
答案 0 :(得分:0)
您在定义它们的同一选择中的表达式中使用列别名。您还在select
中混合聚合函数,该函数没有group by
。
也许这会解决您的问题:
WITH . . .
SELECT c.*, sum_rtn / nullif(sum_lag_risk2, 0) as stat,
stddev(sum_rtn / nullif(sum_lag_risk2, 0)) over () as bias
FROM (SELECT c.*,
sum(wgt_rtn) over (partition by c.ENGINE_ASOF_CALENDAR_DATE) as sum_rtn,
sum(risk_lag) over (partition by c.ENGINE_ASOF_CALENDAR_DATE) as sum_risk_lag,
sum_risk_lag/sqrt(260) over (partition by c.ENGINE_ASOF_CALENDAR_DATE) as sum_lag_risk2
FROM c
) c
ORDER BY c.ENGINE_ASOF_CALENDAR_DATE desc
我不确定应该将标准偏差划分为什么。这是所有数据。