ClickHouse SQL: Assign Total Increase Values to Dates
You can use the following ClickHouse SQL code to assign each element of the 'total_increase' array to the corresponding date in the 'ts' array. This provides a clear breakdown of active app counts over time:
SELECT ts,
total_increase,
total_increase[i] as total_increase_num
FROM
(
SELECT groupArray(Ds) as t,
groupArray(app_count) as total_increase
from (
SELECT min_Ds as Ds,
count(distinct AppIdentifier) as app_count
FROM (
select AppIdentifier,
min(Ds) as min_Ds
from log_iMonkey_iOS_overview
GROUP BY AppIdentifier
)
GROUP BY min_Ds
order by min_Ds
)
) ARRAY
JOIN t as ts,
arrayEnumerate(t) as i where ts >= toDate(#monthly_active_new_business.start#)
This code accomplishes the following:
- Calculates Daily Active App Counts: It queries the 'log_iMonkey_iOS_overview' table to determine the number of distinct 'AppIdentifier's for each minimum 'Ds' (date). This provides a daily count of active apps.
- Groups and Aggregates: The results are grouped by 'Ds' and aggregated using
groupArrayto create arrays of dates ('t') and corresponding active app counts ('total_increase'). - Joins and Enumerates: The generated arrays are joined with a 'ts' alias for the dates and an 'i' alias for an enumerated index. This ensures each date has a corresponding index.
- Assigns Values: The
total_increase[i]expression directly accesses the element from the 'total_increase' array at the index corresponding to each date, resulting in a 'total_increase_num' column where each date has the correct active app count.
This query allows you to easily analyze and visualize how the number of active apps has changed over time.
原文地址: https://www.cveoy.top/t/topic/oDqk 著作权归作者所有。请勿转载和采集!