Hi,
My table contains two fields std_id & course. data is given as under:
std_id course
===============
12 c
15 java
15 vb
13 java
13 c
14 cobol
14 java
15 c
=======================================================
i want to select the students id who has registered for java and C only means output = 13 from the above data.
10:39:15 SQL> L
1 select student_id
2 from my_table
3 where course in ('java','c')
4 group by student_id
5* having count(distinct course) = 2
10:39:18 SQL> /
STUDENT_ID
----------
13
15
Once again Big Thanks to akkerend.
PHP Code:
Another method:
select student_id
from
(
select student_id ,
sum(case
when course = 'c' then 1
else 0
end) c_count,
sum(case
when course = 'java' then 1
else 0
end) java_count,
sum(case
when course <> 'java' and course <> 'c' then 1
else 0
end) oth_count
from my_table
group by student_id
)
where c_count =1 and java_count=1 and oth_count = 0
/
~
Tamil
Last edited by tamilselvan; 08-25-2004 at 01:45 PM.
select student_id from (
select distinct student_id,
count(*) over (partition by student_id) courses
from my_table
where course in ('java','c'))
where courses = 2;
Bookmarks