-- SELECT toStartOfDaytoDateTimeDs AS datetime_day_Ds-- countDISTINCT AppIdentifier AS index_appidentifier_0-- FROM log_iMonkey_iOS_overview-- WHERE Ds = toDateTime#accumulated_access_servicesstart#
以下是修改后的SQL查询:
SELECT toDate(Ds) AS datetime_day_Ds, count(DISTINCT AppIdentifier) AS index_appidentifier_0 FROM log_iMonkey_iOS_overview WHERE Ds >= toDateTime(#accumulated_access_services.start#) AND Ds <= toDateTime(#accumulated_access_services.end#) GROUP BY datetime_day_Ds ORDER BY datetime_day_Ds DESC LIMIT 5000;
SELECT toDate(min_Ds) AS ts, sum(app_count) as total_num FROM ( SELECT AppIdentifier, min(Ds) as min_Ds, count(DISTINCT AppIdentifier) as app_count FROM log_iMonkey_iOS_overview WHERE Ds >= toDateTime(#accumulated_access_services.start#) AND Ds <= toDateTime(#accumulated_access_services.end#) GROUP BY AppIdentifier ORDER BY min_Ds ) GROUP BY ts HAVING ts >= toDate(#accumulated_access_services.start#) ORDER BY ts;
主要修改包括:
-
第一个查询中使用了toStartOfDay和arraySlice函数,这两个函数在第二个查询中不需要,因此去掉了这两个函数。
-
第二个查询中的语法错误是因为缺少了一个SELECT关键字。正确的写法是将第一个SELECT和第二个SELECT合并为一个查询,并在第二个SELECT中加上SELECT关键字。同时,修改了查询中的一些细节,例如将日期时间转换为日期、使用sum函数替代arraySum和arrayEnumerate函数等
原文地址: https://www.cveoy.top/t/topic/g1fn 著作权归作者所有。请勿转载和采集!