Re: How to GROUP results BY month - Mailing list pgsql-sql

From Mark Roberts
Subject Re: How to GROUP results BY month
Date
Msg-id 1216170907.26739.219.camel@localhost
Whole thread Raw
In response to Re: How to GROUP results BY month  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Responses Re: How to GROUP results BY month
Re: How to GROUP results BY month
List pgsql-sql
On Tue, 2008-07-15 at 14:31 +0200, A. Kretschmer wrote:
> am  Tue, dem 15.07.2008, um 13:12:39 +0100 mailte Oliveiros Cristina folgendes:
> > 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?
> 
> ... group by extract(month from date)
> 
> 
> Andreas

It's worth noting that extract(month from timestamp) returns a month_no, and thus will not be suitable for grouping
queriesthat span years.
 

I recommend group by date_trunc('month', <<timestamp field>>)

-Mark



pgsql-sql by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: How to GROUP results BY month
Next
From: "Scott Marlowe"
Date:
Subject: Re: How to GROUP results BY month