2016-08-18 77 views
0

我想在下面的查询中聚集的数组(不工作)插入聚合成阵列

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 

它抛出一个语法错误

+2

'ARRAY [计数(...),...]作为series'? – Ryan

回答

1

瑞安是正确的,你在做什么这样做是一个集合体(array_agg)消耗另一个(count)。这是不正确的。

尝试ARRAY[..]的建议。