Re: SQL Question

From: Thomas J. Kyte <tkyte_at_us.oracle.com>
Date: 2000/04/21
Message-ID: <8dpniv$abj$1_at_nnrp1.deja.com>#1/1


In article <8dpmnv$9l4$1_at_nnrp1.deja.com>,   pol15_at_my-deja.com wrote:
> Given the query ...
>
> select dept_no, count(*)
> from emp
> group by dept_no
>
> this will give me the number of employees in each department.
>
> is there any way to amend the SQL that it will only return rows where
> the department has more than 2 employees?
>
> eg. where count(*) > 2
>
> Any help is greatly appreciated.
>
> Pol.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

the having clause is used to evaluate predicates on aggregates. the query could be:

select dept_no, count(*)
  from emp
 group by dept_no
HAVING COUNT(*) > 2

--
Thomas Kyte                              tkyte_at_us.oracle.com
Oracle Service Industries
http://osi.oracle.com/~tkyte/index.html
--
Opinions are mine and do not necessarily reflect those of Oracle Corp


Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Fri Apr 21 2000 - 00:00:00 CEST

Original text of this message