Re: Returning rows as columns

From: "codeWarrior" <gpatnude(at)hotmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Returning rows as columns
Date: 2005-11-08 16:19:58
Message-ID: dkqj28$18cu$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)gmail(dot)com> wrote in message
news:1131446104(dot)767844(dot)57070(at)f14g2000cwb(dot)googlegroups(dot)com(dot)(dot)(dot)
> 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
>

Browse pgsql-sql by date

  From Date Subject
Next Message Jaime Casanova 2005-11-08 19:01:09 Re: Extract date from week
Previous Message lucas 2005-11-08 11:25:11 Extract date from week