我想在以下查询中获取聚合数组(这不起作用)
select
c.app_id,
90 as interval,
'day_of_week' as group,
array_agg(
count(extract(dow from c.inserted_at) = 0 or null),
count(extract(dow from c.inserted_at) = 1 or null),
count(extract(dow from c.inserted_at) = 2 or null),
count(extract(dow from c.inserted_at) = 3 or null),
count(extract(dow from c.inserted_at) = 4 or null),
count(extract(dow from c.inserted_at) = 5 or null),
count(extract(dow from c.inserted_at) = 6 or null)
) as series
from conversations c
left join apps a on c.app_id = a.id
where c.inserted_at::date > (current_date - (90 || ' days')::interval)::date
group by app_id
抛出语法错误
答案 0 :(得分:1)
Ryan是对的,你正在做的是一个聚合(array_agg
)消耗另一个(count
)。那不对。
按照建议尝试ARRAY[..]
。