Professional Documents
Culture Documents
Question 1.
a. Create the above tables with the given specifications and constraints.
Table no. 1
Query:
Desc Colleges;
Table no. 2
Page-1
Author name : Suhel Daimi
Query:
DESC Staffs;
Table no. 3
Page-2
Author name : Suhel Daimi
Query:
CREATE TABLE StaffJoins(sid NUMBER(10),
cname VARCHAR2(20),
dept VARCHAR2(20),
DOJ DATE,
post VARCHAR2(20),
salary NUMBER(10) );
DESC StaffJoins;
Table no. 4
Page-3
Author name : Suhel Daimi
Query:
create table Teachings ( sid number(10), class varchar2(10), paperid number(10), fsession date ,
tsession date );
desc Teachings;
Table no. 5
Page-4
Author name : Suhel Daimi
Query:
create table Subjects ( paperid number(10) primary key, subject varchar2(10), paperno
number(10), papername varchar2(10));
desc Subjects;
Page-5
Author name : Suhel Daimi
Question 2. Insert about 10 rows as are appropriate to solve the following queries.
Table-colleges
Query:
insert all
Page-6
Author name : Suhel Daimi
10 row(s) inserted
Table – staffs
Query:
insert all
Page-7
Author name : Suhel Daimi
10 row(s) inserted.
Table - staffjoins
Query:
insert all
Page-8
Author name : Suhel Daimi
10 row(s) inserted
Table-Teaching
Query:
insert all
Page-9
Author name : Suhel Daimi
Table – Subjects
Query:
insert all
Page-10
Author name : Suhel Daimi
10 row(s) inserted
Page-11
Author name : Suhel Daimi
select sname from staffs where sid in (select sid from Teachings where paperid in (select
paperid from Subjects where subject in ('DBMS')));
Question 4 List the name and cities of all staffs working in your college.
Query:
Page-12
Author name : Suhel Daimi
Question 5 . List the name and cities of all staffs working in your college who earn
more than 15,000
Query:
Question 6. 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 : Suhel Daimi
Page-14
Author name : Suhel Daimi
Question 10. 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');
Question 11. 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 : Suhel Daimi
Question 12. 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);
Page-16
Author name : Suhel Daimi
select cname from clg_staffs where cname not in (select cname from min_clg);
final output:
Page-17
Author name : Suhel Daimi
Question 13. 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 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 : Suhel Daimi
Question 14. 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
Question 15. Find the college that has the smallest payroll
Query:
create view payroll as(select cname,sum(salary) sal from staffJoins group by cname);
Page-19
Author name : Suhel Daimi
Select cname from payroll where cname not in(select distinct(y.cname) from payroll x,payroll y
where x.sal < y.sal);
Page-20