Friday, February 17, 2012

Rozenshtein question 10(sql cookbook)

all students only taking 2 particular courses  - a cleaner approach IMHO
select s.sno,s.sname,
sum(case  when  t.cno in('CS112', 'CS114') then 1 else 0 end)
from student s inner join take t on  t.sno = s.sno
group by s.sno,s.sname
having sum(case when  t.cno in('CS112', 'CS114') then 1 else 0 end) = 2
and  count(*) = 2

No comments:

Post a Comment