Re: Count of counts

From: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 1996/10/16
Message-ID: <32647797.74695256_at_dcsun4>#1/1


On Thu, 03 Oct 1996 15:33:30 -0700, Leif Neland <leif_at_roskildebc.dk> wrote:

>I need to make a count of counts. I want to know how many students are
>taking how many classes.
>I start by doing:

select classes, count(student_id)
from ( select student_id, count(class_id) classes

         from ...
        where ...
        group by student_id )

group by classes
/

should do it in v7.1 and up.....

>SELECT student_id,count(class_id)
>WHERE...
>GROUP BY student_id;
>
>I then get a list like
>STUDENT_ID COUNT(CLASS_ID)
>---------- ---------------
>1254 3
>1358 3
>1359 2
>2401 1
>
>But how do I get to the result:
>
>CLASSES COUNT(...)
>------- ----------
> 1 1
> 2 1
> 3 2
>
>I can get by by creating a table from the first query, do a query on
>that
>table, and finally dropping that table, but would like to avoid this
>method
>
>Leif Neland
>Systems administrator
>Roskilde Business College
>Denmark
>

Thomas Kyte
Oracle Government
tkyte_at_us.oracle.com                          

http://govt.us.oracle.com

  • Check out Oracle Governments web site! ----- Follow the link to "Tech Center" and then downloadable Utilities for some free software...

statements and opinions are mine and do not necessarily reflect the opinions of Oracle Corporation Received on Wed Oct 16 1996 - 00:00:00 CEST

Original text of this message