Skip site navigation (1) Skip section navigation (2)

Re: How to GROUP results BY month

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Oliveiros Cristina" <oliveiros(dot)cristina(at)marktest(dot)pt>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to GROUP results BY month
Date: 2008-07-15 21:57:54
Message-ID: dcc563d10807151457o43c97aa7mc234a02cb37abb73@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
On Tue, Jul 15, 2008 at 6:12 AM, Oliveiros Cristina
<oliveiros(dot)cristina(at)marktest(dot)pt> wrote:
> Howdy, all,
>
> I have a problem.
>
> I have a table which one of the fields is of type date.
>
> I need to obtain the totals of the other fields in a  by-month basis
> IS there any easy way to do this using the GROUP BY or any other construct?
>

In addition to the responses on grouping by extract('month' from
timestamp) you can also index on this function as long as timestamp
isn't timestamp with timezone.  With that index in place, grouping by
month can be pretty fast even for large datasets covering many months.

In response to

Responses

pgsql-sql by date

Next:From: Mark RobertsDate: 2008-07-16 01:15:07
Subject: Re: How to GROUP results BY month
Previous:From: Jonah H. HarrisDate: 2008-07-15 13:59:22
Subject: Re: Rollback in Postgres

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group