You are on page 1of 51

Author name : Suryakant MasterProgramming.

in

Question 1.

Using the following database :-


college ( cname , city, address, phone, afdate)
staffs (sid, sname, saddress, contects)
staffjoins(sid, cname, dept, DOJ, post, salary)
teachings (sid, class, paperid, fsession, tsession)
subjects (paperid, subject, paperno. , papername)

write SQL statement for the following :-

a. Create the above tables with the given specifications and constraints.

Table no. 1

Query:

Create table Colleges ( cname varchar2(20) primary key, city varchar2(20),


Address varchar2(20), phone number(11), afdate date);

Desc Colleges;

Page-1
Author name : Suryakant MasterProgramming.in

Table no. 2

Query:

CREATE TABLE Staffs( sid NUMBER(20) PRIMARY KEY,


sname VARCHAR2(30),
saddress VARCHAR2(50),
contacts NUMBER(15));

DESC Staffs;

Page-2
Author name : Suryakant MasterProgramming.in

Table no. 3

Query:
CREATE TABLE StaffJoins(sid NUMBER(10),
cname VARCHAR2(20),
dept VARCHAR2(20),
DOJ DATE,
post VARCHAR2(20),
salary NUMBER(10) );

DESC StaffJoins;

Page-3
Author name : Suryakant MasterProgramming.in

Table no. 4

Query:

create table Teachings ( sid number(10), class varchar2(10), paperid number(10), fsession date ,
tsession date );

desc Teachings;

Page-4
Author name : Suryakant MasterProgramming.in

Table no. 5

Query:

create table Subjects ( paperid number(10) primary key, subject varchar2(10), paperno
number(10), papername varchar2(10));

desc Subjects;

Page-5
Author name : Suryakant MasterProgramming.in

b. Insert about 10 rows as are appropriate to solve the following queries.


Table-colleges

Query:

insert all

into colleges values ('pcps','Raipur','aashirwad tower',07712645788,'06-jul-09')

into colleges values ('Science college','Raipur','G.E. ROAD',0878676723,'30-jun-98')

into colleges values ('amity','Raipur','Randri',07712645344,'12-feb-11')

into colleges values ('durga','Raipur','Aamapara',07712645987,'07-jun-89')

into colleges values ('daga','Raipur','Devandra nagar',07712698765,'06-jul-98')

into colleges values ('princess college','Raipur','',07712645788,'06-jul-09')

into colleges values ('disha','Raipur','Chankhuri',07712645456,'06-jul-10')

into colleges values ('BIT college','Durg','Civil line',07712645456,'06-jul-09')

into colleges values ('Central college','Durg','Civil line',6790765752,'30-jun-02')

into colleges values ('Genesis college','Dhamtari','Sadar',8798098789,'06-dec-02')

select * from dual;

10 row(s) inserted

select * from colleges;

Page-6
Author name : Suryakant MasterProgramming.in

Table – staffs

Query:

insert all

into staffs values (1101,'Abhay','Raipur',9076780967)

into staffs values (1102,'Sonam','Dhamtari',9809876787)

into staffs values (1103,'Lavanya','Raigarh',7898909898)

into staffs values (1104,'Raghu','Raipur',6789898790)

into staffs values (1105,'Rahul','Kanker',7898797365)

into staffs values (1106,'Vijay','Durg',6745356798)

into staffs values (1107,'Madhu','Raipur',8976453212)

into staffs values (1108,'Suman','Dhamtari',8945098765)

into staffs values (1109,'Ravi','Durg',9078563412)

into staffs values (1110,'Heena','Bhilai',9087654321)

select * from dual;

10 row(s) inserted.

Page-7
Author name : Suryakant MasterProgramming.in

select * from staffs;

Table - staffjoins

Query:

insert all

into staffjoins values (1101,'amity','science','01-jul-00','HOD',50000)

into staffjoins values (1102,'daga','maths','05-jun-02','professor',30000)

into staffjoins values (1103,'durga','computer','06-nov-08','asst. prof.',40000)

into staffjoins values (1104,'disha','computer','07-jul-99','HOD',45000)

into staffjoins values (1105,'Science college','computer','07-jul-99','professor',25000)

into staffjoins values (1106,'Central college','maths','11-jun-05','professor',30000)

into staffjoins values (1107,'Genesis college','science','13-aug-17','professor',30000)

into staffjoins values (1108,'pcps','electronics','01-jul-16','HOD',45000)

into staffjoins values (1109,'BIT college','commerce','27-nov-01','asst. prof.',35000)

into staffjoins values (1110,'Science college','maths','30-jul-09','professor',25000)

Page-8
Author name : Suryakant MasterProgramming.in

select * from dual;

10 row(s) inserted

select * from staffjoins;

Table-Teaching

Query:

insert all

into Teachings values (1101,'bca-1',1101,'01-jul-00','02-mar-01')

into Teachings values (1102,'bca-3',1103,'01-jun-01','15-sep-01')

into Teachings values (1103,'bsc-1',1102,'01-jan-02','01-oct-02')

into Teachings values (1104,'bca-2',2202,'01-apr-03','15-sep-03')

into Teachings values (1105,'bsc-2',3301,'15-jun-99','15-may-99')

into Teachings values (1106,'bsc-3',3302,'02-oct-04','20-dec-04')

into Teachings values (1107,'bsc-1',3303,'01-jan-98','01-jan-99')

into Teachings values (1108,'bca-2',2201,'02-sep-06','01-jan-07')

Page-9
Author name : Suryakant MasterProgramming.in

into Teachings values (1109,'bcom-1',2203,'01-jan-00','20-dec-00')

into Teachings values (1110,'bca-1',2205,'05-dec-04','25-apr-05')

select * from dual;

select * from teachings;

Table – Subjects

Query:

insert all

into Subjects values (1101,'DBMS',08,'internals')

into Subjects values (1103,'C++',18,'internals')

into Subjects values (1102,'DBMS',28,'internals')

into Subjects values (2202,'C',13,'internals')

into Subjects values (3301,'C++',10,'internals')

into Subjects values (3302,'DBMS',12,'internals')

into Subjects values (3303,'C++',24,'internals')

Page-10
Author name : Suryakant MasterProgramming.in

into Subjects values (2201,'OS',27,'internals')

into Subjects values (2203,'C',14,'internals')

into Subjects values (2205,'OS',21,'internals')

select * from dual;

10 row(s) inserted

select * from Subjects;

Page-11
Author name : Suryakant MasterProgramming.in

c. List the name of the teachers teaching computer subject.


Query:

select sname from staffs where sid in (select sid from Teachings where paperid in (select
paperid from Subjects where subject in ('DBMS')));

d. List the name and cities of all staffs working in your college.
Query:

select staffs.sname,staffs.saddress from colleges,staffs,staffJoins where colleges.cname =


'Science college' and colleges.cname = staffJoins.cname and staffJoins.sid = staffs.sid;

Page-12
Author name : Suryakant MasterProgramming.in

e. List the name and cities of all staffs working in your college who earn more than
15,000
Query:

select staffs.sname,staffs.saddress from colleges,staffs,staffjoins where colleges.cname =


'Science college' and colleges.cname = staffJoins.cname and staffJoins.sid = staffs.sid and
staffJoins.salary > 15000;

f. find the staffs whose name start with 'm' or 'r' and ends with 'a' and\ or 7 character
long.
Query:

select sname from staffs where sname like 'M%a' or sname like 'R%a' or vsize(sname) = 7;

Page-13
Author name : Suryakant MasterProgramming.in

g.Find the staffs whose date of joining is 2005.


Query:
select sname from Staffs,StaffJoins where Staffs.sid = StaffJoins.sid and StaffJoins.DOJ like
'%%-%%%-05';

h. Modify the database so that staffs N1 now works in C2 college.


Query:
update staffJoins set cname = 'daga' where sid = 1101;

Page-14
Author name : Suryakant MasterProgramming.in

i.List the name of subjects, which T1 teacher in this session or all the sessions.
Query:
select subject from subjects,teachings where teachings.sid = 1102 and ( teachings.fsession like
'%%-%%%-%%' or teachings.fsession like '%%-%%-19');

j. Find the classes that T1 do not teach at present session.


Query :
select class from teachings where class <>(select class from teachings where sid=1);

Page-15
Author name : Suryakant MasterProgramming.in

j(a).Find the college who have most number of staffs.


Query:

create view clg_staffs as (select cname,count(sid) staffs from staffjoins group by cname);

create view min_clg as (select distinct(c1.cname) from clg_staffs c1,clg_staffs c2


where c1.staffs<c2.staffs);

select * from clg_staffs c1,clg_staffs c2 where c1.staffs<c2.staffs;

Page-16
Author name : Suryakant MasterProgramming.in

select cname from clg_staffs where cname not in (select cname from min_clg);

final output:

Page-17
Author name : Suryakant MasterProgramming.in

j(b). Find the staffs that earn a higher salary who earn greater than average salary of their
college.
Query:

create view avg_salary as (select cname,avg(salary) avg_sal from StaffJoins group by cname);

select * from avg_salary;

Select st.sid,st.cname,st.salary,av.avg_sal from StaffJoins st,avg_salary av where st.cname =


av.cname and st.salary>av.avg_sal;

Select sname from staffs where sid in (select st.sid from StaffJoins st, avg_salary av where
st.cname =av.cname and st.salary > av.avg_sal);

Page-18
Author name : Suryakant MasterProgramming.in

j(c). Find the college whose average salary is more than average salary of C2 college.
Query:

Select cname from avg_salary where avg_sal > (select avg_sal from avg_salary where

cname = 'Science college' );

j(d). Find the college that has the smallest payroll

Query:

select cname,sum(salary) sal from staffJoins group by cname;

create view payroll as(select cname,sum(salary) sal from staffJoins group by cname);

Page-19
Author name : Suryakant MasterProgramming.in

select distinct(y.cname) from payroll x,payroll y where x.sal < y.sal;

Select cname from payroll where cname not in(select distinct(y.cname) from payroll x,payroll y
where x.sal < y.sal);

Page-20
Author name : Suryakant MasterProgramming.in

j(e). Find the college where the total salary is greater than the average salary of all college.
Query:

create view sal1 as (select avg(salary) avg,cname from staffjoins group by cname);

View created.

create view sal2 as (select sum(salary) avg,cname from staffjoins group by cname);

View created.

select max(avg) from sal1;

select * from sal2 where avg > (select max(avg) from sal1);

Page-21
Author name : Suryakant MasterProgramming.in

j(f). List maximum, average ,minimum salary of each college.


Query:
select cname,max(salary),avg(salary),min(salary) from staffjoins group by cname;

j.f(a).List the names of the teachers, departments teaching in more than one department.
Query:

select staffs.sname,staffjoins.dept from staffs,staffjoins where staffs.sid = staffjoins.sid

and staffs.sid in (select sid from staffjoins group by sid having count(dept)>1);

Page-22
Author name : Suryakant MasterProgramming.in

j.f(b). Acquire details of staffs by name in a college or each college.


Query:

select sname,saddress,contacts,cname,dept,post,salary from staffs,staffjoins where staffs.sid =


staffjoins.sid;

j.f(c). Find the names of staff that earn more than each staff of C2 College.
Query:

create view more as select sname,salary,cname from staffs,staffjoins where staffs.sid =


staffjoins.sid ;

view created.

Page-23
Author name : Suryakant MasterProgramming.in

select * from more;

create view d as (select sname,salary,cname from more where cname='Science college' and
salary not in(select distinct(a.salary) from more a,more b where a.salary<b.salary and
a.cname='Science college' and b.cname='Science college'));

view created.

select * from d;

select distinct(more.sname),more.salary from more,d where more.salary>d.salary;

Page-24
Author name : Suryakant MasterProgramming.in

j.f(d). Give all principals a 10% rise in salary unless their salary becomes greater
than20,000 in such case give 5% rise.
Query:

update staffjoins s set s.salary = s.salary + salary * case when salary < 20000 then 0.1 else 0.05
end where s.post='HOD';

3 rows updated.

select * from staffjoins;

Page-25
Author name : Suryakant MasterProgramming.in

j.f(e). Find all staff that do not work in same cities as the colleges they work.
Query:
select staffs.sname,colleges.city,staffs.saddress,colleges.cname from colleges,staffs,staffjoins
where colleges.cname = staffjoins.cname and staffs.sid = staffjoins.sid and
staffs.saddress<>colleges.city;

j.f(f). List names of employees in ascending order according to salary who are working in
your college or all colleges.
Query:

select staffs.sname,staffjoins.salary,colleges.cname from staffs,colleges,staffjoins where


colleges.cname = staffjoins.cname and staffs.sid=staffjoins.sid order by staffjoins.salary asc;

j.f.f(a).Create a view having fields sname, cname, dept, DOJ, and post.
Query :
create view data as(select
staffs.sname,staffjoins.cname,staffjoins.dept,staffjoins.DOJ,staffjoins.post from staffs,staffjoins
where staffs.sid=staffjoins.sid);
view created.

Page-26
Author name : Suryakant MasterProgramming.in

select * from data;

j.f.f(b). Create a view consisting of cname, average salary and total salary of all staff in
that college.
Query :

create view data2 as (select cname,avg(salary) average_salary,sum(salary) total_salary from


staffjoins group by cname);

view created;

select * from data2;

j.f.f(c).Select the colleges having highest and lowest average salary using above views.

Query :

For lowest salary :

select average_salary,cname from data2 where average_salary = (select min(average_salary)


from data2);

Page-27
Author name : Suryakant MasterProgramming.in

For highest salary :

select average_salary,cname from data2 where average_salary = (select max(average_salary)


from data2);

j.f.f(d). List the staff names of a department using above views.


Query :

select dept,sname from data;

Page-28
Author name : Suryakant MasterProgramming.in

Question- 2

Using the following database :-


Enrollment (enrollno, name, gender, DOB, address, phone)
Admission (admno, enrollno, course, yearsem, date, cname)
Colleges (cname, city, address, phone, afdate)
FeeStructure (course, yearsem, fee)
Payment (billno, admno, amount, pdate, purpose)

write SQL statement for the following :-

a. Create the above tables with the given specifications and constraints.

Table –Enrollment

create table Enrollment (enrollno number(10) primary key, name varchar2(20), gender
varchar2(10), DOB date , address varchar2(20), phone number(10));

table created.

Page-29
Author name : Suryakant MasterProgramming.in

Table –Adimission

Query :

create table Admission (admno number(10) primary key,enrollno number(10),foreign


key(enrollno) references Enrollment(enrollno),course varchar2(20),yearsem varchar2(15),adate
date,cname varchar2(30));

table created.

desc Admission;

Page-30
Author name : Suryakant MasterProgramming.in

Table-Colleges

Desc Colleges;

Table-FeeStructure

create table FeeStructure(course varchar2(20),yearsem varchar2(20),fee number(10),constraint


pk_sem_course primary key(course,yearsem));

table created.

desc FeeStructure;

Table –Payment

create table Payment(billno number(10) primary key,admno number(10),amount


number(15),pdate date,purpose varchar2(20) );

table created.

desc Payment;

Page-31
Author name : Suryakant MasterProgramming.in

b. Insert about 10 rows as are appropriate to solve the following queries.

Table –Enrollment

insert all

into Enrollment values(4101,'Paridhi','female','06/nov/00','Bhilai',9484949444)

into Enrollment values(4102,'anshul','male','16/aug/99','Raipur',9344949444)

into Enrollment values(4103,'khushi','female','14/jan/98','Dhamtari',9564949444)

into Enrollment values(4104,'vimal','male','07/jun/01','Rilaspur',9784949444)

into Enrollment values(4105,'surya','male','07/jul/99','Dhamtari',9904949444)

into Enrollment values(4106,'Vikram','male','19/feb/96','Jagdalpur',9481249444)

into Enrollment values(4107,'shreya','female','05/mar/97','Raipur',9483449444)

into Enrollment values(4108,'sudha','female','30/oct/00','Raipur',9485649444)

into Enrollment values(4109,'aman','male','13/feb/97','Bilaspur',9486749444)

into Enrollment values(4110,'bhawna','female','16/may/99','Bhilai',9488949444)

Page-32
Author name : Suryakant MasterProgramming.in

select * from dual;

10 row(s) inserted.

select * from Enrollment;

Table-Admission

insert all

into Admission values(55501,4104,'BBA','II','17/aug/19','Science college')

into Admission values(55502,4102,'BSC','II','07/aug/18','durga')

into Admission values(55503,4103,'BCA','I','02/jul/19','disha')

into Admission values(55504,4101,'BSC','III','05/aug/17','BIT college')

into Admission values(55505,4105,'BCA','II','28/jun/18','Science college')

into Admission values(55506,4106,'BCA','II','13/jul/18','Science college')

into Admission values(55507,4107,'BCA','I','02/aug/19','daga')

into Admission values(55508,4108,'BCA','III','15/aug/17','central college')

into Admission values(55509,4109,'BBA','I','27/jun/19','amity')

into Admission values(55510,4110,'BSC','I','07/aug/19','Science college')

select * from dual;


Page-33
Author name : Suryakant MasterProgramming.in

10 row(s) inserted.

select * from Admission;

Table-colleges

select * from colleges;

Table-FeeStructure

Page-34
Author name : Suryakant MasterProgramming.in

insert all

into FeeStructure values('BBA','I',21000)

into FeeStructure values('BBA','II',12000)

into FeeStructure values('BBA','III',30000)

into FeeStructure values('BSC','I',10000)

into FeeStructure values('BSC','II',15000)

into FeeStructure values('BSC','III',13000)

into FeeStructure values('BCA','I',3000)

into FeeStructure values('BCA','II',5000)

into FeeStructure values('BCA','III',7000)

into FeeStructure values('MCA','I',10000)

select * from dual;

10 row(s) inserted.

select * from FeeStructure;

Table-Payment

insert all

Page-35
Author name : Suryakant MasterProgramming.in

into Payment values(334411,55501,11000,'16/aug/19','half fees')

into Payment values(334556,55502,12000,'17/jul/19','annual fees')

into Payment values(321345,55503,2500,'8/jul/19','monthly fees')

into Payment values(321789,55504,5000,'2/aug/19','half fess')

into Payment values(324556,55505,7500,'3/aug/19','half fees')

into Payment values(334422,55506,1000,'5/jul/19','monthly fees')

into Payment values(335577,55507,3000,'8/aug/19','annual fees')

into Payment values(553300,55508,5000,'8/jul/19','annual fees')

into Payment values(555410,55509,7000,'16/jul/19','annual fees')

into Payment values(789876,55510,5000,'8/jul/19','half fees')

select * from dual;

10 row(s) inserted.

select * from Payment;

c. Get full detail of all student who look admission this year class wise.

Query :

Page-36
Author name : Suryakant MasterProgramming.in

select name,gender,DOB,address,phone from Enrollment,Admission where Enrollment.enrollno


= Admission.enrollno and Admission.adate like '%%-%%%-19';

d.Get detail of student who took admission in Bhilai colleges.

Query:

select * from Enrollment where enrollno in (select enrollno from Admission where cname in
(select cname from colleges where city='Durg') );

e .Calculate the total amount of fees collected in this session.

(i) By your college

Query :

Page-37
Author name : Suryakant MasterProgramming.in

select Admission.cname,sum(Payment.amount) from Admission,Payment where


Admission.admno = Payment.admno and Payment.pdate like '%%-%%%-19' group by
Admission.cname having Admission.cname = 'Science college';

(ii) By each college

Query :

select Admission.cname,sum(Payment.amount) from Admission,Payment where


Admission.admno = Payment.admno and Payment.pdate like '%%-%%%-19' group by
Admission.cname;

Page-38
Author name : Suryakant MasterProgramming.in

(iii) By all college

Query :

select sum(Payment.amount) from Admission,Payment where Admission.admno =


Payment.admno and Payment.pdate like '%%-%%%-19';

e(a) . List the student who have not payed full fee

i). in your college

Query :

select name,amount,FeeStructure.course,fee,cname from


Payment,Enrollment,Admission,FeeStructure where Admission.admno = Payment.admno and
Enrollment.enrollno = Admission.enrollno and Admission.course = FeeStructure.course and
FeeStructure.yearsem = Admission.yearsem and Payment.amount < FeeStructure.fee and
cname='Science college';

ii).in all college

Page-39
Author name : Suryakant MasterProgramming.in

Query :

select name,amount,FeeStructure.course,fee,cname from


Payment,Enrollment,Admission,FeeStructure where Admission.admno = Payment.admno and
Enrollment.enrollno = Admission.enrollno and Admission.course = FeeStructure.course and
FeeStructure.yearsem = Admission.yearsem and Payment.amount < FeeStructure.fee;

e(b) . List the number of admission in your class in every year.

Query :

create view adm_count as select admno,course,yearsem,substr(adate,8,2)ayear from Admission;

view created.

select * from adm_count;

Page-40
Author name : Suryakant MasterProgramming.in

select ayear,count(admno) from adm_count group by (ayear);

e(c). List the student in the session who are not in the colleges in the same city as they live
in.

Query :

select Enrollment.name,Enrollment.address studentcity,Admission.cname


studentcollege,Colleges.city collegecity,admission.adate from Enrollment,Admission,Colleges

where Enrollment.enrollno = Admission.enrollno and Admission.cname = Colleges.cname and


Enrollment.address <> Colleges.city and substr(adate,8,2) = 19;

Page-41
Author name : Suryakant MasterProgramming.in

e(d). List the student in colleges in your city and also live in your city.

Query :

select Enrollment.name,Admission.cname studentcollege,Enrollment.address studentcity from


Enrollment,Admission,Colleges where Enrollment.enrollno = Admission.enrollno and
colleges.cname=Admission.cname and Enrollment.address='Raipur' and colleges.city = 'Raipur';

Question- 3
Create the following database,
Subjects (paperid, subject, paper, papername)
Test (paperid, date, time, max, min)
Score (rollno, paperid, marks, attendence)
Students (admno, rollno, class, yearsem)

a. Create the above tables with the given specifications and constraints.

Page-42
Author name : Suryakant MasterProgramming.in

Table- Subjects

desc Students;

Table-Test

Query :

create table Test (paperid number(10) primary key, tdate date, time varchar2(10) , max
number(10), min number(10) );

Table created.

desc Test;

Table-Score

Query :

create table Score (rollno number(10) primary key, paperid number(10), marks number(10),
attendence varchar2(10) );

Table created.

desc Score;

Page-43
Author name : Suryakant MasterProgramming.in

Table-Students

Query ;

create table Students (admno number(10) primary key, rollno number(10), class varchar2(10),
yearsem varchar2(10) );

Table created.

desc Students;

b.Insert about 10 rows as are appropriate to solve the following queries.

Table-Subjects

Select * from Subjects;

Page-44
Author name : Suryakant MasterProgramming.in

Table-Tset

insert all

into Test values(1101,'30-aug-19','10:30',80,27)

into Test values(1102,'13-nov-19','1:10',80,27)

into Test values(1103,'07-dec-19','12:30',80,27)

into Test values(2202,'15-sep-19','2:20',80,27)

into Test values(3301,'3-aug-19','10:30',80,27)

into Test values(3302,'14-dec-19','1:10',80,27)

into Test values(3303,'19-nov-19','12:30',80,27)

into Test values(2201,'5-oct-19','2:20',80,27)

into Test values(2203,'8-nov-19','10:30',80,27)

into Test values(2205,'23-nov-19','10:30',80,27)

select * from dual;

10 row(s) inserted.

select * from Test;

Page-45
Author name : Suryakant MasterProgramming.in

Table-Score

insert all

into Score values(44101,1101,50,'present')

into Score values(44102,1102,0,'absent')

into Score values(44103,1103,45,'present')

into Score values(44104,2202,16,'present')

into Score values(44105,3301,0,'absent')

into Score values(44106,3302,13,'present')

into Score values(44107,3303,0,'absent')

into Score values(44108,2201,70,'present')

into Score values(44109,2203,66,'present')

into Score values(44110,2205,0,'absent')

select * from dual;

10 row(s) inserted.

select * from Score;

Page-46
Author name : Suryakant MasterProgramming.in

Table-Students

insert all

into Students values(55501,44101,'BCA','II')

into Students values(55502,44102,'BCA','III')

into Students values(55503,44103,'BCA','I')

into Students values(55504,44104,'BSC','II')

into Students values(55505,44105,'BSC','III')

into Students values(55506,44106,'BCA','II')

into Students values(55507,44107,'BCA','II')

into Students values(55508,44108,'BCA','III')

into Students values(55509,44109,'BSC','I')

into Students values(55510,44110,'BCA','II')

select * from dual;

10 row(s) inserted.

select * from Students;

Page-47
Author name : Suryakant MasterProgramming.in

c. List all student who are present in a paper of a subject.

Query :

select Students.rollno,Score.attendence from Students,Score where

Score.rollno =Students.rollno and Score.attendence = 'present';

d. List all roll numbers who have passed in first division.

Page-48
Author name : Suryakant MasterProgramming.in

Query :

select rollno,marks from Score where marks >= 50;

e. List all student in BCA-II who have scored higher than average

i). in your college

Query :

create view merge_info as select Enrollment.name, Admission.cname, Students.class,

Students.yearsem, Score.marks from Score,Enrollment,Admission,Students where


Enrollment.enrollno = Admission.enrollno and Admission.admno = Students.admno and
Score.rollno= Students.rollno;

view created.

select * from merge_info where cname='Science college' and class = 'BCA' and yearsem = 'II';

select * from merge_info where cname='Science college' and class = 'BCA' and

yearsem = 'II' and marks > (select avg(marks) from Score);

Page-49
Author name : Suryakant MasterProgramming.in

ii) in every college

Query :

select * from merge_info where class = 'BCA' and yearsem = 'II' and marks > (select avg(marks)
from Score);

f. List the highest score,average score and minimum score in BCA-II

i) in your college

Query :

create view score_info as select max(marks)max_score,avg(marks) avg_score,min(marks)


min_score from Score;

view created.

select * from score_info;

select * from merge_info,score_info where class = 'BCA' and yearsem = 'II' and cname =
'Science college';

Page-50
Author name : Suryakant MasterProgramming.in

ii)in every college

Query :

select * from merge_info,score_info where class = 'BCA' and yearsem = 'II';

Page-51

You might also like