Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: group by count

Re: group by count

From: <pollachi_at_my-deja.com>
Date: Thu, 01 Feb 2001 17:24:27 GMT
Message-ID: <95c63u$v3a$1@nnrp1.deja.com>

Use the HAVING clause

SELECT employee_id, count(1)
FROM employee
GROUP BY employee_id
HAVING count(1) > n

In article <95c2sk$rl4$1_at_nnrp1.deja.com>,   fsconzo_at_my-deja.com wrote:
> Greetings all:
>
> I haven't been using Oracle that long but thought something like this
> would be pretty simple to do:
>
> I want to select the count of rows that have the same value in a
> particular column but only where the count is greater than zero.
>
> Example:
>
> select count(*), employee_id from employee group by employee_id;
>
> This might return:
> COUNT(*) EMPLOYEE_ID
> ---------- -----------
> 1 1
> 2 4
> 1 5
> 1 6
> 1 7
> 1 8
>
> but my database actually returns hundreds of thousands of rows. I want
> to filter the results to only show rows where the count > 1.
>
> This doesn't work: select count(*), employee_id from employee group by
> employee_id where count(*) > 1;
>
> I thought a subselect with a name on the count column might work, but
> that won't work:
>
> select idcount, employee_id from (select count(*) "idcount",
> employee_id from employee group by employee_id) where idcount > 1;
>
> It returns an invalid column name error.
>
> Anyone have any ideas?
> Perhaps I could create a temp table to do this - but I don't know how
> to create temp tables in oracle 8i.
>
> Any help would be appreciated.
> Best Regards,
> Frank Sconzo
>
> Sent via Deja.com
> http://www.deja.com/
>

Sent via Deja.com
http://www.deja.com/ Received on Thu Feb 01 2001 - 11:24:27 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US