您可以使用HAVING子句来筛选出PlatformType = 5的数据,并且使用COUNT函数来获取对应的数据数量。然后在SELECT子句中使用CASE语句来判断当PlatformType = 5时,index_avgdevicetime_0的值应该是sum(AvgDeviceTime)除以PlatformType = 5对应的数据数量。以下是修改后的SQL查询语句:

SELECT toStartOfDay(toDateTime(Ds)) AS datetime_day_Ds, PlatformType AS PlatformType, sum(AvgDeviceTime) AS index_avgdevicetime_0, CASE WHEN PlatformType = 5 THEN sum(AvgDeviceTime) / COUNT(*) END AS index_avgdevicetime_5 FROM log_iMonkey_Wechat_overview WHERE Debug = 0 AND PlatformType != 0 AND Ds >= toDateTime(#day_device_ave_wechat_time.start#) AND Ds <= toDateTime(#day_device_ave_wechat_time.end#) GROUP BY datetime_day_Ds, PlatformType HAVING PlatformType = 5 OR PlatformType != 5 ORDER BY datetime_day_Ds DESC, PlatformType DESC LIMIT 5000;

这样,当PlatformType = 5时,会输出对应的数据数量,并且index_avgdevicetime_0的值是sum(AvgDeviceTime)除以PlatformType = 5对应的数据数量

SELECT toStartOfDaytoDateTimeDs AS datetime_day_Ds PlatformType AS PlatformType sumAvgDeviceTime AS index_avgdevicetime_0FROM log_iMonkey_Wechat_overviewWHERE Debug = 0 AND PlatformType != 0 AND Ds

原文地址: https://www.cveoy.top/t/topic/hXX3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录