SELECT SUMcnt AS total_count Ds FROM SELECT COUNTDISTINCT AppIdentifier AS cnt Ds FROM log_iMonkey_iOS_overview GROUP BY Ds UNION ALL SELECT COUNTDISTINCT AppIdentifier AS cnt Ds
To ensure that the total_count calculated by SUM(cnt) is a monotonically increasing value with the increase of Ds, you can modify the code as follows:
SELECT SUM(cnt) AS total_count, Ds FROM ( SELECT COUNT(DISTINCT AppIdentifier) AS cnt, Ds FROM log_iMonkey_iOS_overview GROUP BY Ds UNION ALL SELECT COUNT(DISTINCT AppIdentifier) AS cnt, Ds FROM log_iMonkey_Android_overview WHERE PlatformType != 0 AND AppIdentifier != 'identifier' GROUP BY Ds UNION ALL SELECT COUNT(DISTINCT PlatformType) AS cnt, Ds FROM log_iMonkey_Wechat_overview WHERE PlatformType != 0 AND Ds <= 'current_date' GROUP BY Ds ) AS subquery GROUP BY Ds ORDER BY Ds ASC;
In the last UNION ALL subquery, I added a condition `AND Ds <= 'current_date'` to filter the rows with Ds less than or equal to the current date. This ensures that only the counts of PlatformType up to the current date are included in the calculation of total_count.
Also, I added an ORDER BY clause to sort the result by Ds in ascending order to demonstrate the monotonically increasing total_count
原文地址: https://www.cveoy.top/t/topic/h8c7 著作权归作者所有。请勿转载和采集!