| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL count problem
select  frequency, tot_amount
from
(select regnr, count(distinct rowid) frequency, sum(amount) tot_amount
 from table
 group by regnr
)
order by frequency desc
--
Sybrand Bakker, Oracle DBA
Frank Heijmans <no_ftgh_at_xs4all.nl_spam> wrote in message
news:387deca0.26725177_at_news.xs4all.nl...
> Hi,
>
> I am looking for an SQL solution to do a frequency count
> on a table. My table could look like this:
>
> regnr         amount
> -------------------------------
> 123           100.00
> 345           50.00
> 456           60.00
> 123           25.00
> 456           15.00
> 123           200.00
>
>
> The count should give me the following result
>
> frequency     tot_amount
> --------------------------------
> 3             225.00
> 2             85.00
> 1             15.00
>
>
> Is this possible in one query? If so, can someone help me?
>
> Regards,
>
> Frank
>
Received on Thu Jan 13 2000 - 09:23:48 CST
![]()  | 
![]()  |