[英]How to avoid using aggregation function in another aggregation function in ClickHouse
I want to get the average number of days between creation user profile ads_clients_data.create_date
and the first day of its posts min(ads_data.time)
.我想获得创建用户配置文件ads_clients_data.create_date
与其帖子的第一天之间的平均天数min(ads_data.time)
。
I wrote the following SQL statement:我写了以下SQL语句:
select
avg(dateDiff(dd, ads_clients_data.create_date, ads_data.time),
min(ads_data.time))
from
ads_data
inner join
ads_clients_data on ads_clients_data.client_union_id = ads_data.client_union_id;
But it is impossible to use min in avg function.但是不可能在 avg 函数中使用 min 。 It is the first time I worked with ClickHouse and would be very thankful if someone can help me.这是我第一次与 ClickHouse 合作,如果有人能帮助我,我将非常感激。
If I follow you correctly, you can use two levels of aggregation:如果我正确地跟随您,您可以使用两个级别的聚合:
select avg(datediff(dd, c.create_date, d.min_time)
from (
select client_union_id, min(ads_data.time) min_time
from ads_data
group by client_union_id
) d
inner join ads_clients_data c on c.client_union_id = d.client_union_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.