Re: SQL question

From: rich <richard.rubinstein.nospam_at_ihsenergy.com>
Date: Wed, 16 Aug 2000 12:40:36 +0100
Message-ID: <399a7fc3$1_at_news.star.co.uk>


Terry,

Assuming you always have four and only four records per product then the following should give the result you want.

select
product,

max(decode(level_no,1,code,null)) lvl1,
max(decode(level_no,2,code,null)) lvl2,
max(decode(level_no,3,code,null)) lvl3,
max(decode(level_no,4,code,null)) lvl4

from your_table
group by product

Rich

terry_stjean_at_my-deja.com wrote in message <8n9f2u$bpj$1_at_nnrp1.deja.com>...
>I have a table which contain 4 records per product. The 4 records
>represent the products hierarchy codes. A sequence number identifies
>the hierarchy level.
>e.g. Product Level Code
> A 1 A2
> A 2 C4
> A 3 10
> A 4 01
>Is it possible in SQL to reformat this to the following:
>Product Lvl1 Lvl2 Lvl3 Lvl4
> A A2 C4 10 01
>
>Then I will join this onto our main sales file.
>
>Terry
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
Received on Wed Aug 16 2000 - 13:40:36 CEST

Original text of this message