S02045
错误代码
S02045
报错信息
The PARTITION/ORDER BY column 'xxx' must be included in the GROUP BY clause. RefId: S02045
错误原因
由于 DolphinDB 允许在 GROUP BY 子句中为列指定别名,当查询语句中同时使用了分析函数和 GROUP BY 语句时,系统会检查 PARTITION BY 和 ORDER BY 子句中是否引用了 GROUP BY 子句中指定的原始列或其表达式(如 val+1)。如果未引用或者引用了别名列,则会抛出该报错。
id = `XOM`GS`AAPL
val = 102.1 33.4 73.6
date = 2020.01.01 2020.01.02 2020.01.01
t = table(id, val, date);
select min(max(val)) over (partition by date) from t group by date;
/*
date min
---------- -------------------
2020.01.01 102.099999999999994
2020.01.02 33.399999999999998
*/
select min(max(val)) over (partition by date order by id) from t group by date;
// select min(max(val)) over (partition by date order by id asc range between unbounded preceding and current row) as min from t group by date => The PARTITION/ORDER BY column 'id' must be included in the GROUP BY clause. RefId:S02045
select min(max(val)) over (partition by id) from t group by date as id;
// select min(max(val)) over (partition by id range between unbounded preceding and unbounded following) as min from t group by date as id => The PARTITION/ORDER BY column 'id' must be included in the GROUP BY clause. RefId:S02045
解决办法
分析函数与 GROUP BY 子句连用时,注意 PARTITION BY 和 ORDER BY 子句中必须正确引用 GROUP BY 子句指定的列。