DBMS Assignment5
DBMS Assignment5
Lab Assignment – 5
1. IDs and names of students who have applied to major in CS at some
college.
SELECT sid , sname from student where sid in ( select sid from apply where
major = 'cs' );
2. Find ID and name of student having same high school size as Jay.
select sid , sname from student where sizeHS in ( select sizeHS from student
where
sname = 'Jay' ) ;
3. Find ID and name of student having same high school size as Jay but
result should not include Jay.
select sid , sname from student where sizeHS in ( select sizeHS from student
where
sname = 'Jay' ) and sname not in ( 'Jay' );
4. Find the name of student with their GPA and Sid whose GPA not equal
to GPA of Irene?
select sid , sname , gpa from student where gpa not in ( select gpa from student
where
sname = 'Irene' );
5. Find college where any student having their name started from J have
applied?
select cname from apply where sid in ( select sid from student where
sname like 'J%' );
6. Find all different major where Irene has applied?
select distinct major from apply where sid in ( select sid from student where
sname = 'Irene' );
7. Find IDs of student and major who applied in any of major Irene had
applied to?
select distinct sid , major from apply where major in ( select major from apply
where sid in
( select sid from student s1 where sname = 'Irene' )) ;
8. Find IDs of student and major who applied in any of major Irene had
applied to? But this me exclude Irene sID from the list.
select distinct sid , major from apply where major in( select major from apply
where sid in
( select sid from student where sname = 'Irene' )) and sid not in ( select sid from
student
where sname = 'Irene' );
9. Give the number of colleges Jay applied to? (Remember count each
college once no ma er if he applied to same college twice with different
major).
select count ( distinct cname ) from apply where sid in ( select sid from student
where
sname = 'Jay' );
10.Find sID of student who applied to more or same number of college
where Jay has applied?
select sid from apply where cname in ( select cname from apply where sid in (
select sid
from student where sname = 'Jay' )) ;
11.Find details of Students who applied to major CS but not applied to
major EE? (sID 987, 876, 543 should only be include in result).
select * from student where sid in ( select sid from apply where major = 'CS'
MINUS select
sid from apply where major = 'EE' );
12.All colleges such that some other college is in same state. (Cornell
should not be part of result as no other college in New York Hint: use
exists).
select cname from college c1 where exists ( select state from college c2 where
c1 . state = c2 . state and c1 . cname != c2 . cname );
13.Find the college with highest enrollment.
select cname , enrollment from college c1 where not exists ( select enrollment from
college
c2 where c1 . enrollment < c2 . enrollment );
14.Find name of student having lowest GPA.
select sname from student s1 where not exists ( select sname from student s2
where
s1 . gpa > s2 . gpa );
15.Find the most popular major.
select major , count ( sid ) from apply group by major having
count ( sid ) = ( select
max ( count ( sid )) from apply group by major );
16.Find sID, sName, sizeHS of all students NOT from smallest HS.
select sid , sizehs , sname from student where sizehs != ( select min ( sizehs )
from student ) ;
17.Find the name of student who applies to all the colleges where sID 987
has applied?(Hint: see Query Find IDs of student applied to all
colleges).
select sname , sid from student where not exists ( select distinct cname from
apply where
sid = 987 minus select distinct cname from apply where sid = student . sid );
18.Find college where all the student have applied.
select cname from college c where not exists (( select sid from student s ) minus (
select sid
from apply a where a . cname =c . cname ));
19.Find sid of student who have not applied to Stanford.
select sid from student minus select distinct sid from apply where cname =
'Stanford' ;