ERROR [HY000] ERROR: Aggregate function calls may not be nested */

ERROR [HY000] ERROR: Aggregate function calls may not be nested */

添加到我的查询时我无法使下面的行工作,有什么想法吗? 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

您在表达式中使用列别名的定义位置相同 select。您还在没有 group by.

select 中混合聚合函数

也许这会解决您的问题:

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

我不确定标准差应该按什么划分。这是所有数据。