DBMS Module 2
DBMS Module 2
1.
2.
a. Write an SQL query to fetch the EmpId and FullName of all the
employees working under the Manager with id – ‘986’.
b. Write an SQL query to fetch the different projects available from the
EmployeeSalary table.
c. Write an SQL query to find the employee id whose salary lies in the
range of 9000 and 15000.
d. Write an SQL query to fetch the employees whose name begins with any
two characters, followed by a text “hn” and ends with any sequence of
characters.
ii) For each project retrieve the project number, project name and
number of employees who worked on that project.
R1 ←PROJECT pnumber=pnoWORKS_ON
R2←π pnumber, pname, count(*) (R1)
iii) Retrieve the names of employees who work on all the project
controlled by department 5
DEPT5_PROJS ← ρ(Pno)(πPnumber(σDnum=5(PROJECT)))
EMP_PROJ ← ρ (Ssn, Pno) (πEssn, Pno (WORKS_ON))
RESULT_EMP_SSNS ← EMP_PROJ ÷ DEPT5_PROJS
RESULT ← πLname, Fname (RESULT_EMP_SSNS * EMPLOYEE)
vi) Retrieve the name and address of all employees who work for
'sports' department.
R1← ρ DNAME=’sports’(DEPT)
ii) Find the age of the youngest sailor who is eligible to vote (i.e. is
atleast 18 years old) for each rating level with atleast two such
sailors.
Select s.rating,MIN(s.age)
from sailors s
where s.age>18
group by s,rating
having 1 < (SELECT COUNT (*)
FROM Sailors s2
WHERE s.rating=s2.rating);
iii) Find the names of sailors who have not reserved a red boat. (use
nested query).
SELECT S.sname
FROM Sailors S
WHERE S.sid NOT IN ( SELECT R.sid
FROM Reserves R
WHERE R.bid IN ( SELECT B.bid
FROM Boats B
WHERE B.color=`red’ ));
iv) Compute increments for the rating of persons who have sailed two
different boats on the same day.
SELECT r.sid, r.day, COUNT(*), s.rating
FROM reserves r
JOIN sailors s
ON r.sid=s.sid
GROUP BY day
HAVING COUNT(r.day)=2;
3. Find the passenger names for those who do not have any bookings
in any flights
Π pname ((Π pid (passenger) - Π pid (booking)) ⨝ passenger)
4. Get the details of flights that are scheduled on both dates
01/12/2020 and 02/12/2020 at 16:00 hours
(σ fdate = 01/12/2020 ^ time = 16:00 (flight)) ∩ (σ fdate = 02/12/2020 ^ time = 16:00 (flight))
5. Find the details of all male passengers who are associated with jet
agency.
Π passengers.pid, pname, pcity (σ pgender = “Male” ^ aname =
‘Jet’ (passengers ⨝ booking ⨝ agency))
2. Find the names of all employees in the database who do not work for
First Bank Corporation'. Assume that all people work for exactly one
company
select employee_name from works where company_name != ’First Bank
Corporation’;
3. Find the names of all employees in the database who earn more that
every employee of Small Bank Corporation'. Assume that all people
work for at most one company
select employee_name from works where salary > all (select salary from
works where company_name = ’Small Bank Corporation’);
4. Find the name of the company that has the smallest payroll
select company-name from works group by company-name having sum
(salary) <= all (select sum (salary) from works group by company-name);
5. Find the names of all employees in the database who live in the same
cities and on the same streets as do their managers.
select P.employee-name from employee P, employee R, manages M
where P.employee-name = M.employee-name and M.manager-name =
R.employee-name and P.street = R.street and P.city = R.city;
8.
ANSWERS:
9.
ANSWERS
10.
ANSWERS
11.
ANSWERS