Re: How to GROUP results BY month

From: Herouth Maoz <herouth(at)unicell(dot)co(dot)il>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to GROUP results BY month
Date: 2008-07-15 12:39:54
Message-ID: 487C9A9A.1040107@unicell.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Oliveiros Cristina 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?
Yes, use date_trunc( 'month', time_stamp ).

Example:

select count(*),date_trunc( 'month', time_stamp ) from rb group by
date_trunc( 'month', time_stamp );

Herouth

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jonah H. Harris 2008-07-15 13:59:22 Re: Rollback in Postgres
Previous Message Herouth Maoz 2008-07-15 12:32:15 Re: How to GROUP results BY month