Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SELECT STATEMENT
Manny,
You may try something like this:
select switch "Switch-column",sum(n1) "On-Total", sum(n2) "Off-Total"
from
(select switch,
to_number(decode(position,'On','1','0')) n1,
to_number(decode(position,'Off','1','0')) n2
from s)
group by switch;
Regards,
Paul
"JM" <riper_at_yahoo.com> wrote in message
news:P7hz4.31817$t7.1892238_at_news1.rdc2.tx.home.com...
> I have following table:
>
> Switch-column position-column Time
> switchA On 1:00
> switchA Off 2:00
> switchD On 1:00
> switchB Off 1:00
> switchD Off 2:00
> switchC Off 1:00
> switchC Off 2:00
> =============================
> I need following output:
>
> Switch On-Total Off-Total
> switchA 1 1
> SwitchB 0 1
> SwitchC 0 2
> SwitchD 1 1
> ==============================
> As above the output is grouped by Switch column. I can't figure out how
to
> split
> position-column into "on-total' and "off-total" columns using SELECT
> statement.
>
> Thanks in advance!
> Manny
>
>
Received on Mon Mar 13 2000 - 21:46:56 CST