Skip to content
Advertisement

Postgres SUM over given time

I am trying to SUM google analytics data over a given time using Postgres. I am not quite sure how to get around a grouping issue. The query you see below returns one column per day. I want to SUM all clicks over the given dates. So the query should return 1 row for each campaign with a column on each row indicating the sum of clicks.

I can write the query so that it returns the number for the entire month as seen below:

Any help would be greatly appreciated. Thanks!

Advertisement

Answer

The query you see below returns one column per day. I want to SUM all clicks over the given dates. So the query should return 1 row for each campaign with a column on each row indicating the sum of clicks.

So just remove the date from the select and group by clauses:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement