Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: column to row (computed)

Re: column to row (computed)

From: Jusung Yang <JusungYang_at_yahoo.com>
Date: 26 Oct 2002 10:13:49 -0700
Message-ID: <130ba93a.0210260913.19de8560@posting.google.com>


You probably left out something. Otherwise you practically have answered your own question. This logic would get the job done.

> select key, sum (case when State = "STATE1" then + Value
> when State = "STATE2" then - Value)
> from tab1
> group by key

garodiar_at_yahoo.com (Ritesh G.) wrote in message news:<1ada02e0.0210251510.5f0c01b5_at_posting.google.com>...
> hi,
>
> I wanted to know if one can do following with one/two/more SQL select
> statements, (may be using some oracle functions also)
>
> Suppose there is a table tab1 as
>
> Key State Value
> =======================
> P1 STATE1 Value1
> P1 STATE2 Value2
> P2 STATE1 Value3
> P2 STATE2 Value4
>
> Now the result desired is following with two columns
>
> P1 (Value1 - Value2) ie { STATE1 - STATE2}
> P2 (Value3 - Value4) ie { STATE1 - STATE2}
>
> In short for each key in table we get (state, value) pairs, then get a
> computed state based on state values and rule as 'STATE1's Value -
> 'STATE2's Value.
>
> Something like
>
> select key, sum (case when State = "STATE1" then + Value
> when State = "STATE2" then - Value)
> from tab1
> group by key
>
> Thanks
> Ritesh
> garodiar_at_yahoo.com
Received on Sat Oct 26 2002 - 12:13:49 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US