ASS5

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

GLA UNIVERSITY , MATHURA

Name : ISHU AGRAWAL

Section : CA

Roll No. : 24

University Roll No. : 2315510088

Course : BTECH. CS ( AIML & IOT )

Subject : DATABASE MANAGEMENT SYSTEM LAB

Subject Code : BCSC 0762

Assignment : 05

Faculty : MR. SURENDRA KUMAR


1. IDs and names of students who have applied to major in CS
at some college.
Ans. select sid,sname from student where sid in (select sid
from apply where major='CS');

2. Find ID and name of student having the same high school


size as Jay.
Ans. select sid,sname from student where sizehs in (select
sizehs from student where sname='Jay');

3. Find ID and name of student having the same high school


size as Jay but result should not include Jay.
Ans. select sid,sname from student where sizehs in (select
sizehs from student where sname='Jay') and sname!='Jay';
4. Find the name of student with their GPA and Sid whose GPA
not equal to GPA of Irene?
Ans. select 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?
Ans. select cname from college where cname in (select cname
from apply where sid in (select sid from student where sname
like 'J%'));
6. Find all different major where Irene has applied?
Ans. select 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?
Ans. select sid,major from apply where major in (select major
from apply where sid in (select sid from student where
sname='Irene'));
8. Find IDs of student and major who applied in any of major
Irene had applied to? But this time exclude Irene sID from the
list.
Ans. select 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 matter if he applied to the same
college twice with different major)
Ans. select 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?
Ans. select sid from apply group by sid having
(count(cname)>=(select count(distinct 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)
Ans. select * from student where sid in(select sid from apply
where major='CS') and sid not in(select sid from apply where
major='EE');
12. All colleges such that some other college is in the same
state. (Cornell should not be part of the result as no other
college in New York Hint: use exists)
Ans. select cname from college where state in (select state from
college group by state having count(state)>1);

13. Find the college with the highest enrollment.


Ans. select cname from college where enrollment in (select
max(enrollment) from college);

14. Find the name of student having the lowest GPA.


Ans. select sname from student where gpa in(select min(gpa) from
student);
15. Find the most popular major.
Ans. select major from apply group by major having count(*) in (select
max(count(*)) from apply group by major);

16. Find sID, sName, sizeHS of all students NOT from the
smallest HS
Ans. select sid,sname,sizehs from student where sizehs not in (select
min(sizehs) from student);
17. Find the name of the student who applies to all the colleges
where sID 987 has applied?(Hint: see Query Find IDs of
student applied to all colleges)
Ans. select sName from Student where SID in (select sID from Apply
where cName in (select cName from Apply where sID in (987)) group by
SID having count(distinct cName) = (select count(distinct cName) from
Apply where sID in (987)));

18. Find the college where all the students have applied.
Ans. select cName from College where (select count(distinct SID) from
Student)=(select count(distinct sID) from Apply where Apply.cName =
College.cName);

19. Find sid of students who have not applied to Stanford.


Ans. select distinct sid from apply where sid not in(select sid from apply
where cname='Stanford');
20. Find sid of Students that applied to both Stanford and
Berkeley.
Ans. select distinct sid from apply where sid in (select sid from apply
where cname = 'Stanford') and sid in (select sid from apply where
cname = 'Berkeley');

21. Give a list of all names including all names of colleges and
students.
Ans. select distinct sname from student union select distinct cname
from college;

22. Create a table ApplicationInfo having columns sID: int,


sName:varchar2(10), and number_of_applications: number(2)
they filed? Populate this table with appropriate data using the
insert command.
Ans. create table ApplicationInfo (sID INT,sName
VARCHAR2(10),number_of_applications NUMBER(2));
23. Create a table ApplicationData and load with ID, name, and
college where they applied with the state of the college
(remember to include details of ALL students that have applied
or not applied) on runtime using a single query.
Ans. create table applicationdata as select s.sid, s.sname, a.cname as
college, c.state from student s left join apply a on s.sid = a.sid left join
college c on a.cname = c.cname;

24. Stanford decides not to take any student who has also
applied to its rival Berkeley turn their application decision to
N.
Ans. update apply set decision = 'N' where cname = 'Stanford' and sid in
(select sid from apply where cname = 'Berkeley');

25. Delete applications that are filed to the city ‘New York’.
Ans. delete from apply where cname in (select cname from college
where state = 'NY');

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy