Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Query Hint
On Feb 11, 11:16 pm, ciccio <cic..._at_ciccio.it> wrote:
> Vince wrote:
> >> I have a ORDERS table as follows:
> [...]
> >> select department, level, count(*) as QUANTITY from orders
> > If the number of levels is fixed a rather simple approach would be:
> > select department,
> > sum(decode(level,1,quantity,0)) as level_1,
> > sum(decode(level,2,quantity,0)) as level_2,
> > ...
> > from orders
> > ...
> > group by department
>
> Yes, but I have to compute also quantity (count(*)) in the same query,
> i.e. I need to know for each department how many orders are at a certain
> step, how many at another step and so on.
>
> How can I modify this query in order to achieve this result?
>
> Thanks.
Just add a similar sum column, but instead of using quantity, use 1. ie. sum(decode(level,1,1,0)) as level_1_count Received on Mon Feb 12 2007 - 09:34:17 CST
![]() |
![]() |