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

Home -> Community -> Usenet -> c.d.o.tools -> Re: Selecting rows as columns

Re: Selecting rows as columns

From: Mark <ars_at_lambic.co.uk>
Date: Fri, 01 Sep 2000 16:52:07 GMT
Message-ID: <39AFDEA8.3DEE3471@lambic.co.uk>

mbraund_at_my-deja.com wrote:
>
> Hi,
>
> I'm trying to generate a select statement. I'll use the following table
> as an example:
>
> Date Date
> Time_Band Varchar2(7)
> Calls Number
>
> Time_Band can take three values (Peak, OffPeak, Weekend). I want to
> query the table and return one row giving the number of calls for each
> timeband.
>
> eg. :
>
> Peak OffPeak Weekend
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 2 3 0

SELECT SUM(DECODE(time_band, 'Peak',    calls, 0) peak
      ,SUM(DECODE(time_band, 'OffPeak', calls, 0) offpeak
      ,SUM(DECODE(time_band, 'Weekend', calls, 0) weekend
FROM mytable; Received on Fri Sep 01 2000 - 11:52:07 CDT

Original text of this message

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