Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Where or Having clause and COUNT(1)

jmchugh-OracleJun 3 2006 — edited Jun 6 2006
I'm having trouble trying to figure out the way to get the conditional difference between two counts in a where clause.

I would like to scan a table and only select records where the record count of one column attribute is different than another.

I have

select name, count(1) from skill <<< TOTAL_COUNT

and

select name, count(1) from skill where score is not NULL <<<< SCORED_COUNT

I want to have a statement that just returns the names for those where TOTAL_COUNT - SCORED_COUNT = 0

... meaning those names where any of the rows have not been scored.

I've tried a "having clause" but it still returns all there names. Even those there TOTAL_COUNT - SCORED_COUNT > 0

Here's the non-working code....

select * from

(select full_name

from emp e
where e.manager = 'Smith, John'
having

((select count(1)
from emp_skill es
where es.emp_fk = e.id
group by null) -

(select count(1)
from emp_skill es1
where es1.emp_fk = e.id and
es1.self_prof is not NULL
group by null)) = 0
)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2006
Added on Jun 3 2006
6 comments
873 views