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

Re: Sorting distinct dates by year and month respectively

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: "Matt Arnilo S(dot) Baluyos \(Mailing Lists\)" <matt(dot)baluyos(dot)lists(at)gmail(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Sorting distinct dates by year and month respectively
Date: 2006-06-07 05:43:31
Message-ID: 20060607054331.29609.qmail@web31804.mail.mud.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
> gsin=> SELECT DISTINCT date_part('year', article_pubdate),
> date_part('month', article_pubdate) FROM articles GROUP BY
> date_part('year', article_pubdate), date_part('month',
> article_pubdate) ORDER BY date_part('year', article_pubdate),
> date_part('month', article_pubdate) DESC;
>  date_part | date_part
> -----------+-----------
>       2002 |         5
> Can anyone help me figure out why this is so?


I believe that date_trunc will give you what you want.

mydb=> select date_trunc('month', tstamp) as month from process group by month order by month
limit 4;
        month
---------------------
 2005-10-01 00:00:00
 2006-01-01 00:00:00
 2006-02-01 00:00:00
 2006-04-01 00:00:00
(4 rows)

Regards,

Richard Broersma Jr.


In response to

pgsql-novice by date

Next:From: Andreas SeltenreichDate: 2006-06-07 10:18:47
Subject: Re: levenshtein contrib installation
Previous:From: Matt Arnilo S. Baluyos (Mailing Lists)Date: 2006-06-07 05:35:01
Subject: Sorting distinct dates by year and month respectively

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