Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: simple query help
I wouldn't necessarily call this a simple query. It's not to tough to
get the count on the status by the dept as follows:
select dept, count(status) active
from dept_dude
where status = 'a'
group by dept;
This will give you the following output:
dept active
=== ====
north 4
east 2
south 2
west 1
Then you could do a similar query for inactive status.
In order to get the results you are after, you have to dig a little deeper into the Oracle bag of tricks. This solution uses the DECODE function which is an Oracle extension that is not supplied by other SQL vendors. In other words it's non-standard:
select dept,
count(decode(status, 'a', status, null)) active, count(decode(status, 'i', status, null)) inactivefrom dept_dude
Happy SQLing,
Gary Fowler
3M Health Information Systems
grfowler_at_mmm.com
Gabriel Millerd wrote:
> i have a table as follows (#1). i would like to have a report
> that gave the following (#2). can anyone help me?
>
> (#1)
>
> dept dude status
> ==== ==== ======
> north, bob, i,
> north, jim, a,
> north, sam, i,
> north, jeff, a,
> north, mary, a,
> north, sal, a,
> east, mary, a,
> east, dwaine, i,
> east, tom, i,
> east, bill, i,
> east, chuck, a,
> south, matt, a,
> south, holly, a,
> west, joy, i,
> west, stacy, a,
>
> (#2)
>
> dept active inactive
> ==== ====== ========
> north 4 2
> east 2 3
> south 2 0
> west 1 1
Received on Wed Dec 29 1999 - 15:26:20 CST
![]() |
![]() |