count in join......

S

SacSan

i have a questing relating to sql, i have a table that has student
enrollment, and i need to find out how many students have enrolled in
the same number of subjects as that of student who's id is '0102',
note the subject could be different , but the final number ie. count.
has to be the same
the best i could come up with was ....

select student_id, count(*)
from student_enroll AS A
where student_id ='0102'
join (select student_id, count(*) from student where student_id <>
'0102' group by student_id) AS B on ...........

now here i need to match the count , but don't know how... , can
somebody please help
 
K

Ken Sheridan

Do it by means of a subquery:

SELECT Student_ID, COUNT (*) As ClassCount
FROM Student_Enroll
GROUP BY Student_ID
HAVING COUNT(*) =
(SELECT COUNT(*)
FROM Student_Enroll
WHERE Student_ID = '0102');

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top