0% found this document useful (0 votes)
7 views

DBMS Assignment5

This document contains 25 SQL queries related to a student application database. The queries find information like student IDs and names who applied to certain majors, students with the same high school size as others, colleges that students applied to, popular majors, and more. It also includes queries to create and populate tables using the application data.

Uploaded by

Unknown XYZ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

DBMS Assignment5

This document contains 25 SQL queries related to a student application database. The queries find information like student IDs and names who applied to certain majors, students with the same high school size as others, colleges that students applied to, popular majors, and more. It also includes queries to create and populate tables using the application data.

Uploaded by

Unknown XYZ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name – Pratibha rana

Univ. Roll no. – 2215001306


Section – AJ
Sub – DBMS LAB

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' ;

20.Find sid of Student that applied to both Stanford and Berkeley.


( select sid from apply where cname = 'Stanford' ) intersect ( select sid from
apply where
cname = 'Berkeley' );
21.Give list of all names including all names of colleges and students.
select sname from student union select cname from college ;

22.Create a table Applica onInfo having columns sID: int, sName:


varchar2(10) and number_of_applica ons: number(2) they filed?
create table ApplicationInfo ( sid int , sname varchar ( 10 ), number_of_applications
numeric ( 2 ));

insert into applicationinfo select s . sid , s . sname , nvl ( a . no_of_application , 0 )


from (( select
sid , sname from student ) s left outer join ( select sid , count ( * ) as
no_of_application from
apply group by sid ) a on s . sid =a . sid );

select * from applicationinfo ;


23.Create table Applica onData and load with ID, name and college where
they applied with state of college (remember to include details of ALL
students that have applied or not applied) on run me using single
query.
create table ApplicationData as ( select distinct sid ,
cname , state from apply natural join
college ) ;
24.Stanford decide not to take any student who have also applied to its
rival Berkeley turn their applica on decision to N.
update apply set decision = 'N' where cname = 'Stanford' and sid
in (( select sid from apply where cname = 'Stanford' )intersect
( select sid from apply where
cname = 'Berkeley' )) ;
25.Delete applica ons that are filed to city ‘New York’.
delete from apply where cname in ( select cname from college where state = 'NY'
);

You might also like