Professional Documents
Culture Documents
21CSB0B20 DBMS Assignment
21CSB0B20 DBMS Assignment
21CSB0B20 DBMS Assignment
Faculty Table -
create table faculty
(
fac_id int primary key,
fac_name varchar(20),
fac_dept varchar(20)
);
Student Table -
create table student_tbl
(
stud_id int primary key,
stud_name varchar(20),
course_id int,
rating varchar(10),
course_name varchar(20),
foreign key(course_id) references faculty(fac_id) on delete set null
);
Good rating -
select fac_id,count(*) as good_rating from faculty
join student_tbl on faculty.fac_id=student_tbl.course_id
where student_tbl.rating=‘good' group by fac_id;
Bad rating -
select fac_id,count(*) as bad_rat from faculty
join student_tbl on faculty.fac_id=student_tbl.course_id
where student_tbl.rating='bad'
group by fac_id;
a)
select fac_name,fac_id from faculty where fac_id not in(
select fac_id from (select fac_id,count(*) as bad_rat from faculty
join student_tbl on faculty.fac_id=student_tbl.course_id
where student_tbl.rating='bad'
group by fac_id)x
where x.bad_rat>1);
b), c)
select fac_name
from (select fac_name from faculty join student_tbl on course_id=fac_id and
rating='good' group by fac_name )
where fac_name not in (select fac_name from faculty join student_tbl on
course_id=fac_id and rating='bad' group by fac_name);
d)
select fac_name from (select fac_name,count(*) as bad_rat from faculty
join student_tbl on faculty.fac_id=student_tbl.course_id
where student_tbl.rating='bad'
group by fac_name)x
where x.bad_rat>=1;
e)
select fac_name from
(select fac_name,count(*) as bad_rat from faculty
join student_tbl on faculty.fac_id=student_tbl.course_id
where student_tbl.rating=‘good' group by fac_name)x
where x.bad_rat>=1;
Parts Table -
create table parts(
pid int,
pname varchar(255),
color varchar(255)
);
Catalog Table -
create table catalog (
suid int,
pid int,
pcost varchar(255)
);
a)
select distinct sname from suppliers where color!=‘blue
b)
select distinct sname from suppliers where color='blue'
minus
select distinct sname from suppliers where color!=‘blue’;
c)
select distinct sname from suppliers where color='blue'
minus
select distinct sname from suppliers where color!=‘blue';
d)
select distinct sname from suppliers where color='blue'
intersect
select distinct sname from suppliers where color!=‘blue';
Student Table -
create table student(
scl_id varchar(255),
scl_rno int primary key,
s_name varchar(255),
s_address varchar(255)
);
School Table -
create table school (
scl_id varchar(255) primary key,
scl_name varchar(255),
scl_address varchar(255),
scl_phn varchar(10)
);
Enrollment Table -
create table enrolment
(
scl_id varchar(255),
scl_rno int,
eroll_no int primary key,
exam_name varchar(255)
);
Exam_Result Table -
insert into exam_result values (1,'exam',100);
insert into exam_result values (2,'exam',98);
insert into exam_result values (3,'exam',100);
insert into exam_result values (4,'exam',100);
insert into exam_result values (5,'exam',98);
insert into exam_result values (6,'exam',100);
a)
select y.scl_name,count(*) as count_of_hundreds from
(select x.scl_name,ex.marks from exam_result ex join (select
s1.scl_id,s1.scl_name,e.eroll_no
from school s1 join enrolment e on s1.scl_id=e.scl_id) x on
ex.eroll_no=x.eroll_no) y
where y.marks=100 group by y.scl_name;
b)
select y.scl_name,count(*) as count_of_hundreds from
(select x.scl_name,ex.marks from exam_result ex join (select
s1.scl_id,s1.scl_name,e.eroll_no
from school s1 join enrolment e on s1.scl_id=e.scl_id) x on
ex.eroll_no=x.eroll_no) y
where y.marks=100 and y.scl_name in
(select x.scl_name from (select s1.scl_name,count(*) as count_of_students from
school s1
c)
select x.scl_name from (select s2.scl_name,count(*) as count_of_students from
student s1 join
school s2 on s1.scl_id=s2.scl_id where s1.scl_id=s2.scl_id group by
s2.scl_name) x where
x.count_of_students>=2;
intersect
select y.scl_name,count(*) as count_of_hundreds from
(select x.scl_name,ex.marks from exam_result ex join (select
s1.scl_id,s1.scl_name,e.eroll_no
from school s1 join enrolment e on s1.scl_id=e.scl_id) x on
ex.eroll_no=x.eroll_no) y
where y.marks=100 group by y.scl_name;