pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: codeWarrior <gpatnude@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Breakdown results by month
Date: Wed, 3 Aug 2005 08:38:18 -0700
Message-ID: <dcqnt9$2rfr$1@news.hub.org> (raw)
References: <2bffcc3305080211342745b1ab@mail.gmail.com>

You are looking for what is commonly referred to as a "pivot-table" or a 
"cross-tab". Pivot-tables are a fairly sophisticated, non-normalized view of 
a dataset, nd most commonly appear in spreadsheets and are used for 
financial or statistical analysis.

These queries typically use an aggregate function (sum, min, max, etc....) 
and a "group by" clause when generated from an SQL query...

There are lots of decent tutorials / samples out there (Google for "Pivot 
Table SQL" and you'll see...)

http://www.windowsitpro.com/Files/09/15608/Listing_01.txt

http://mail.python.org/pipermail/python-list/2005-February/264233.html










"Henry Ortega" <juandelacruz@gmail.com> wrote in message 
news:2bffcc3305080211342745b1ab@mail.gmail.com...
>I have the ff table:
>
> id       |    total    |     effective        |    end_date
> john          6              01-01-2005        02-28-2005
> john          8              03-01-2005        06-30-2005
>
> How can I return:
> id       |    total    |     effective        |    end_date
> john          6              01-01-2005        01-31-2005
> john          6              02-01-2005        02-28-2005
> john          8              03-01-2005        03-31-2005
> john          8              04-01-2005        04-30-2005
> john          8              05-01-2005        05-31-2005
> john          8              06-01-2005        06-30-2005
>
> Any help would be appreciated. Thanks
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
> 





view thread (4+ messages)  latest in thread

Message-ID: <dcqnt9$2rfr$1@news.hub.org>
Permalink:  ../dcqnt9$2rfr$1@news.hub.org/
Also on:    postgresql.org/message-id/dcqnt9$2rfr$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gpatnude@hotmail.com
  Subject: Re: Breakdown results by month
  In-Reply-To: <dcqnt9$2rfr$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox