ClickHouse SQL 错误:嵌套聚合函数解决方案
SELECT toStartOfDay(toDateTime(Ds)) AS datetime_day_Ds,\n PlatformType AS PlatformType,\n sum(max(MergedUrlCount,MergedViewCount)) AS index_avgdevicetime_0\nFROM log_iMonkey_Wechat_overview\nWHERE Debug = 0 AND PlatformType != 0 AND\n Ds >= toDateTime(#day_wechat_views_time.start#)\n AND Ds <= toDateTime(#day_wechat_views_time.end#) \n \nGROUP BY datetime_day_Ds,\n PlatformType\nORDER BY datetime_day_Ds DESC,\n PlatformType DESC\nLIMIT 5000;\n报错errormessage: 运行SQL失败:[500]运行异常: Code: 184. DB::Exception: Aggregate function max(MergedUrlCount, MergedViewCount) is found inside another aggregate function in query: While processing max(MergedUrlCount, MergedViewCount). (ILLEGAL_AGGREGATION) (version 52.3.10.8)\n代码怎么改内容:错误信息显示查询中存在一个聚合函数max(MergedUrlCount, MergedViewCount)嵌套在另一个聚合函数中。根据错误信息,我们需要修改查询以解决这个问题。\n\n以下是修改后的查询代码:\n\n\nSELECT toStartOfDay(toDateTime(Ds)) AS datetime_day_Ds,\n PlatformType AS PlatformType,\n max(MergedUrlCount + MergedViewCount) AS index_avgdevicetime_0\nFROM log_iMonkey_Wechat_overview\nWHERE Debug = 0 AND PlatformType != 0 AND\n Ds >= toDateTime(#day_wechat_views_time.start#)\n AND Ds <= toDateTime(#day_wechat_views_time.end#) \n \nGROUP BY datetime_day_Ds,\n PlatformType\nORDER BY datetime_day_Ds DESC,\n PlatformType DESC\nLIMIT 5000;\n\n\n在修改后的查询中,使用max(MergedUrlCount + MergedViewCount)代替了原来的sum(max(MergedUrlCount,MergedViewCount))。这样做可以解决嵌套聚合函数的问题。注意,这里使用max函数是为了保留原查询中的逻辑,你也可以根据需要选择其他聚合函数,比如sum。
原文地址: https://www.cveoy.top/t/topic/pxvS 著作权归作者所有。请勿转载和采集!