Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Selecting rows as columns
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) weekendFROM mytable; Received on Fri Sep 01 2000 - 11:52:07 CDT