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: Returning rows as columns
Date: Tue, 8 Nov 2005 08:19:58 -0800
Message-ID: <dkqj28$18cu$1@news.hub.org> (raw)
References: <1131446104.767844.57070@f14g2000cwb.googlegroups.com>

You're looking for a technique generally referred to as a "pivot table" 
which is really a non-normalized or aggregate view of relational data....

You'll find plenty of examples if you Google "pivot table".


"Paul" <paulditerwich@gmail.com> wrote in message 
news:1131446104.767844.57070@f14g2000cwb.googlegroups.com...
> Hi,
>
> I'm looking for a way to return rows as columns. My problem is the
> following. I have three tables:
> suppliers,products and productprices. A supplier and a product make a
> productprice. A certain product may have an x number of suppliers and
> prices.
>
> Now I have the following query:
> select
> products.int_artnr,products.str_name,suppliers.str_naam,productprices.flt_price
> from products,productprices,suppliers
> WHERE products.int_artnr = productprices.int_artnr
> AND suppliers.int_crednr=productprices.int_crednr
> ORDER BY int_artnr
>
> This gives me a result but not the one I wanted. I want to have a
> dataset that returns the supplierprice  and suppliername as a column
> behind every product for all suppliers. So you get an x number of
> columns.
>
> Example:
>
> Number Name Suppl1 Price1 Suppl2 Price2
>
> 1 Beer 10 cases Heineken 3.33 Amstel 1.55
> 2 Beer 2 cases Heikenen 1.22
>
>
> Could someone please give me some pointers if this is achievable and if
> yes, how I should do this?
>
> Thx,
>
> Paul
> 





Message-ID: <dkqj28$18cu$1@news.hub.org>
Permalink:  ../dkqj28$18cu$1@news.hub.org/
Also on:    postgresql.org/message-id/dkqj28$18cu$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: Returning rows as columns
  In-Reply-To: <dkqj28$18cu$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