Professional Documents
Culture Documents
Submitted by-
RAHUL SINGH
323/CO/07
COE-II (C3), III Year
Subject Code – COE317
INDEX
Problem 1 Date :
Problem 2 Date :
Problem 3 Date :
MGR is employee number of employee whom the employee reports to. Department
number is foreign key.
A) List all employees who have atleast one person reporting to them.
B) List employee details if and only if more than 5 employees are present in
department number 10.
C) List all employee names with their immediate higher authority.
D) Employees who don’t manage anyone.
E) Employees whose salary > lowest salary of an employee of dept number 20.
F) Employees earning more than highest paid manager.
G) Highest salary paid for each job
H) Most recently hired employee in each department.
I) Year when most people joined the company. Display the year as well as number
of employees.
J) Department having highest renumeration bill.
K) Display a ‘*’ against list of most recently hired employees.
L) Correlated subquerries to list out employees who earn more than avg salary of
their dept.
M) Find nth maximum salary
N) Length of service of each employee.
PROBLEM – 1
Q: Student (srno, rollno, dob, age, dept, marks, name)
select name from students where dept = 'MPA' and marks >= 70; 4)
OUTPUT
name
J
K
5) select rollno, name, marks from students where marks >= ( select
AVG(marks) from students);
OUTPUT
rollno name marks
201 J 78.49
267 F 80.5
297 G 69.67
321 B 71.45
322 C 68.45
323 A 78.45
371 K 79.95
PROBLEM – 2
Q: Student (sid, name, major, credits)
Faculty (fid, fname, rank, dept)
Class (courseno, schedule, fid, room)
Enroll (courseno, sid, grade)
A) Retrieve name, id & number of credits of math major students.
B) Retrieve id and names of students whose course is MPA 304.
C) Retrieve courseno, name and major of students enrolled in course taught by
faculty F110.
D) Retrieve names of students with largest number of credits.
E) Retrieve course in which less than 3 students are enrolled.
F) Change major of student with sid S102 to music.
G) Change room to R211 for courses taught by ABC.
OUTPUT
sid name credits
S100 SA 20
S101 SC 23
S103 SD 23
S104 SE 10
OUTPUT
sid name
S100 SA
S101 SC
S102 SB
S103 SD
S104 SE
OUTPUT
courseno No. of students enrolled
MPA301 3
OUTPUT
sid name major credits
S102 SB Maths 2
___________________________
sid name major credits
S102 SB Music 2
7) select * from class where fid = ( select fid from faculty where
fname = 'ABC');
update class
set room = 'R211'
where
class.fid = ( select fid from faculty where fname = 'ABC');
select * from class where fid = ( select fid from faculty where
fname = 'ABC');
OUTPUT
courseno schedule fid room
MPA304 40 F110 R201
__________________________________
courseno schedule fid room
MPA304 40 F110 R211
PROBLEM – 3
Q: Student (sname, classno, theorymarks, drivingmarks)
Studentdrivingteacher (sname, drivingteachername)
Teachervehicle (drivingteachername, vehicle, theory, practical)
Vehicle (modelyear, vehicle)
A) Retrieve teachers who teach theory and give driving lessons on all vehicles.
B) Retrieve pairs of students satisfying :
iv) Have same marks
v) Have different theory teachers
vi) Have same driving marks but different driving teachers
C) Find students who are neither taught theory nor driving lesson by johnson.
D) Retrieve names of students with more marks than john in driving and theory.
E) Add age in student table.
F) List students having marks >= average theory class marks of class 8.
drivingteachername
John
2)
i) select t.sname , d.sname from students as t, Students as d
where t.theorymarks = d.theorymarks and t.drivingmarks =
d.drivingmarks and t.sname <> d.sname
OUTPUT
sname sname
John SA
SA John
OUTPUT
sname sname
John SA
John SD
John SE
SA John
SA SF
SA SG
SD John
SD SF
SD SG
SE John
SE SF
SE SG
SF SA
SF SD
SF SE
SG SA
SG SD
SG SE
OUTPUT
sname sname
John SA
SA John
OUTPUT
sname
SA
SB
SC
SD
SE
OUTPUT
sname
SC
5) SeLECT * FROM STUDENTS;
alter table students
add age integer
update Students set age = 20 where sname = 'John';
update Students set age = 21 where sname = 'SA' or sname = 'SE' ;
update Students set age = 18 where sname = 'SB' or sname = 'SF';
update Students set age = 16 where sname = 'SC' or sname = 'SG';
update Students set age = 22 where sname = 'SD';
select * from Students
OUTPUT
OUTPUT
sname
John
SA
SC
PROBLEM – 4
Q: Dept (deptno not null number(2), dname varchar(14), loc varchar2(13))
Emp (empno not null number(4), ename varchar2(10), job varchar2(12), mgr
number(4), hiredate date, sal number(7,2), comm number(7,2), deptno number(2))
MGR is employee number of employee whom the employee reports to. Department
number is foreign key.
A) List all employees who have atleast one person reporting to them.
B) List employee details if and only if more than 5 employees are present in
department number 10.
C) List all employee names with their immediate higher authority.
Employees who don’t manage anyone. D)
E) Employees whose salary > lowest salary of an employee of dept number 20.
F) Employees earning more than highest paid manager.
G) Highest salary paid for each job
H) Most recently hired employee in each department.
I) Year when most people joined the company. Display the year as well as number
of employees.
J) Department having highest renumeration bill.
K) Display a ‘*’ against list of most recently hired employees.
L) Correlated subquerries to list out employees who earn more than avg salary of
their dept.
M) Find nth maximum salary
N) Length of service of each employee.
1) select * from Emp where empno in ( select mgr from Emp group by
mgr);
OUTPUT
empno ename job mgr hiredate sal comm deptno
1 A Engineer 22 1999-12-23 7000.56 200.56 10
2 B Engineer 20 2010-11-12 8000.56 200.56 10
20 J Manager NULL 2006-12-12 9000.56 2100.56 20
22 K Manageer NULL 1999-01-03 100.56 2000.56 50
2) select * from emp where deptno = (select deptno from Emp group by
deptno having count(deptno) >= 5)
OUTPUT
empno ename job mgr hiredate sal comm deptno
1 A Engineer 22 1999-12-23 7000.56 200.56 10
2 B Engineer 20 2010-11-12 8000.56 200.56 10
6 F Engineer 20 1996-06-11 17900.56 210.56 10
7 G Engineer 2 1998-10-11 15670.56 210.56 10
8 H Engineer 22 2001-11-23 12340.56 210.56 10
21 I Manager NULL 2002-07-01 27000.56 100.56 10
OUTPUT
subordinate Immediate higher authority
A K
B J
C J
D K
E A
F J
G B
H K
4) select * from emp where emp.empno not in (select mgr from Emp
where mgr is not null)
OUTPUT
empno ename job mgr hiredate sal comm deptno
3 C Trainer 20 2010-02-22 6000.56 270.56 50
4 D Researcher 22 1999-08-09 9000.56 250.56 30
5 E Engineer 1 1996-05-02 17000.56 210.56 30
6 F Engineer 20 1996-06-11 17900.56 210.56 10
7 G Engineer 2 1998-10-11 15670.56 210.56 10
8 H Engineer 22 2001-11-23 12340.56 210.56 10
21 I Manager NULL 2002-07-01 27000.56 100.56 10
5) select * from emp where emp.sal > (select MIN(sal) from Emp where
deptno = 20)
OUTPUT
empno ename job mgr hiredate sal comm deptno
1 A Engineer 22 1999-12-23 7000.56 200.56 10
2 B Engineer 20 2010-11-12 8000.56 200.56 10
3 C Trainer 20 2010-02-22 6000.56 270.56 50
4 D Researcher 22 1999-08-09 9000.56 250.56 30
5 E Engineer 1 1996-05-02 17000.56 210.56 30
6 F Engineer 20 1996-06-11 17900.56 210.56 10
7 G Engineer 2 1998-10-11 15670.56 210.56 10
8 H Engineer 22 2001-11-23 12340.56 210.56 10
21 I Manager NULL 2002-07-01 27000.56 100.56 10
6) select * from emp where emp.sal > (select Max(t.sal) from Emp as t
,emp as d where t.empno = d.mgr)
OUTPUT
empno ename job mgr hiredate sal comm deptno
5 E Engineer 1 1996-05-02 17000.56 210.56 30
6 F Engineer 20 1996-06-11 17900.56 210.56 10
7 G Engineer 2 1998-10-11 15670.56 210.56 10
8 H Engineer 22 2001-11-23 12340.56 210.56 10
21 I Manager NULL 2002-07-01 27000.56 100.56 10
OUTPUT
job Max Salary
Engineer 17900.56
Manager 27000.56
Researcher 9000.56
Trainer 6000.56
8) select ename from emp where hiredate > '2010-01-01'
OUTPUT
ename
B
C
OUTPUT
Year No. of employees
1996 2
1998 1
1999 3
2001 1
2002 1
2006 1
2010 2
OUTPUT
deptno Max remuneration
10 27101.12
20 11101.12
30 17211.12
50 6271.12
11) select '*' + ename as '*Employee' from Emp where (hiredate) >
'2010 - 1 - 1' ;
OUTPUT
*Employee
*B
*C
12) select t.ename , t.sal, t.deptno from emp as t where t.sal >
(select AVG(sal) from emp where t.deptno = deptno group by deptno
)
OUTPUT
ename sal deptno
F 17900.56 10
G 15670.56 10
I 27000.56 10
E 17000.56 30
C 6000.56 50
OUTPUT
ename x
A 3752
B -225
C 38
D 3888
E 5082
F 5042
G 4190
H 3051
I 2831
J 1206
K 4106