2016-08-18 74 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[..]的建議。