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

Re: Querying all months even if don't exist

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Querying all months even if don't exist
Date: 2007-02-26 15:31:03
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
am  Mon, dem 26.02.2007, um 10:10:45 -0500 mailte Robert Fitzpatrick folgendes:
> I have a query that pulls totals for the month and from there I am
> building a crosstab to show all months. My dilemma is that sometimes
> there is no data for a month and the crosstab becomes skewed. I made a
> table with all the 12 months in it and joined to the query in my view to


select ('2007-01-01'::date+(s||'month')::interval)::date from generate_series(0,11)s;

to generate a list of all month in this year. You can use this to join
to other tables.

Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA

In response to

pgsql-general by date

Next:From: Alban HertroysDate: 2007-02-26 15:57:38
Subject: Re: complex referential integrity constraints
Previous:From: Chris ColemanDate: 2007-02-26 15:25:56
Subject: Re: how to sort an array and remove duplicate in plpgsql

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