DBMS AnnualFile
DBMS AnnualFile
Answer:
SQL Query
a. Create the tables
address VARCHAR2(100),
phone VARCHAR2(15),
afdate DATE
);
saddress VARCHAR2(100),
contacts VARCHAR2(15)
);
dept VARCHAR2(50),
DOJ DATE,
1|Page
Shreyansh Yeole BCA II
Database Management System 2024-2025
post VARCHAR2(50),
);
class VARCHAR2(20),
fsession DATE,
tsession DATE,
);
subject VARCHAR2(50),
paperno NUMBER,
papername VARCHAR2(100)
);
FROM Staffs s
2|Page
Shreyansh Yeole BCA II
Database Management System 2024-2025
d. List the names and cities of all staff working in your college (assuming 'C1')
Select s.sname, c.city
FROM staffJoins sj
e. List the names and cities of all staff working in your college who earn more than 15,000
SELECT s.sname, c.city
FROM Staffs s
f. Find the staffs whose names start with 'M' or 'R' and end with 'A' and/or are 7 characters long
SELECT sname
FROM Staffs
WHERE
OR LENGTH(sname) = 7;
FROM Staffs s
h. Modify the database so that staff 'N1' now works in 'C2' College
UPDATE StaffJoins
i. List the names of subjects that 'S1' teaches in this session or all sessions
3|Page
Shreyansh Yeole BCA II
Database Management System 2024-2025
Select sb.subject
From teachings t
j. Find the classes that 's1' does not teach in the present session
SELECT *
FROM Teachings
FROM Colleges c
GROUP BY c.cname
l. Find the staffs who earn a higher salary than the average salary of their
college.
FROM Staffs s
SELECT AVG(salary)
);
m. Find the colleges whose average salary is more than the average salary of C2.
SELECT c.cname
FROM Colleges c
GROUP BY c.cname
SELECT AVG(salary)
FROM StaffJoins
);
FROM (
FROM Colleges c
GROUP BY c.cname
WHERE ROWNUM = 1;
o. Find the colleges where the total salary is greater than the average salary of all colleges.
SELECT c.cname
FROM Colleges c
GROUP BY c.cname
SELECT AVG(total_salary)
FROM (
FROM StaffJoins
GROUP BY cname
);
SELECT c.cname,
MAX(sj.salary) AS max_salary,
AVG(sj.salary) AS avg_salary,
MIN(sj.salary) AS min_salary
FROM Colleges c
GROUP BY c.cname;
5|Page
Shreyansh Yeole BCA II
Database Management System 2024-2025
SELECT s.sid, s.sname, s.saddress, s.contacts, sj.cname, sj.dept, sj.DOJ, sj.post, sj.salary
FROM Staffs s
r. Find the names of staff who earn more than each staff of C2 College.
FROM Staffs s
SELECT sj2.salary
s. Give all principals a 10% salary increase unless it exceeds 20,000; then give a 5% increase.
UPDATE StaffJoins
END
t. Find all staff who do not work in the same city as the colleges they are assigned to.
FROM Staffs s
6|Page
Shreyansh Yeole BCA II
Database Management System 2024-2025
SELECT *
FROM Staffs s
GROUP BY s.sname
7|Page
Shreyansh Yeole BCA II