我有一些稱爲分類的表,其中包含classification_indicator_id
。
我需要總結這個ID
並放入1天系列。
我需要添加大約20列(與另一個classification_indicator_id
)。
我修改了一下回答previous question:generate_series()在PostgreSQL中按預期不能按預期方式工作
select
data.d::date as "data",
sum(c.classification_indicator_id)::integer as "Segment1",
sum(c4.classification_indicator_id)::integer as "Segment2",
sum(c5.classification_indicator_id)::integer as "Segment3"
from
generate_series(
'2013-03-25'::timestamp without time zone,
'2013-04-01'::timestamp without time zone,
'1 day'::interval
) data(d)
left join classifications c on (data.d::date = c.created::date and c.classification_indicator_id = 3)
left join classifications c4 on (data.d::date = c4.created::date and c4.classification_indicator_id = 4)
left join classifications c5 on (data.d::date = c5.created::date and c5.classification_indicator_id = 5)
group by "data"
ORDER BY "data"
但仍然無法正常工作。 sum
對於每一行都是很大的,而且我增加了額外的列。在與4列segment1
爲2013年3月26日第二個表應該像第一張表等
With 3 column With 4 columns
data | Segment1 | Segment2 data | Segment1 | Segment2 | Segment3
-------------------------------- -------------------------------------------
2013-03-25 | 12 | 16 2013-03-25 | 12 | 16 | 20
-------------------------------- -------------------------------------------
2013-03-26 | 18 | 24 2013-03-26 | 108 | 144 | 180
謝謝你,現在我們正在測試這個解決方案,我將讓你知道它是否對我們有幫助。但是我們認爲這是:) – ssuperczynski 2013-04-04 12:57:28
它的工作!我們的速度更快:) – ssuperczynski 2013-04-04 13:13:43
我們將使用這兩種解決方案,他們都很棒。從10000ms到100ms這是它! – ssuperczynski 2013-04-04 13:22:00