Chapter08 B B 2 INSQueries
Chapter08 B B 2 INSQueries
Chapter08 B B 2 INSQueries
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query B: Select the employee tuples whose salary is greater than $30,000.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query C: Select the tuples for all employees who either work in department 4 and make over $25,000 per year, or work
in department 5 and make over $30,000.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query D: Retrieve the last name, first name, and salary of all employees.
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query F: Retrieve a list of all employee names as well as the name of the departments they manage IF they happen to
manage a department .
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query G: Retrieve the first name, last name, and salary of all employees who work in department number 5
OR
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query I: Retrieve a list of names of each female employee and their dependents.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query J: Retrieve the name of the manager of each department.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query L: Aggregate functions.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query M: For each department, retrieve the department number, the number of employees in the department, and
their average salary.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query N: Retrieve each department number, the number of employees in the department, and their average salary,
while renaming the resulting attributes as indicated below: Dno, No_of_employees, Average_sal.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query O: A list of all employee names as well as the name of the departments they manage if they happen to manage a
department.
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
BIGGER QUERIES
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query 1: Retrieve the name and address of all employees who work for the ‘Research’ department.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query 2: For every project located in ‘Stafford’, list the project number, the controlling department number, and the
department manager’s last name, address, and birth date.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query 4: Make a list of project numbers for projects that involve an employee whose last name is ‘Smith’, either as a
worker or as a manager of the department that controls the project.
---------------------------------------------------------------------------------------------------------------------------------------------------------
Query 5. List the names of all employees with more than 2 dependents.
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query 6: Retrieve the names of employees who have no dependents.
SELECT SSN
FROM employee
WHERE SSN NOT IN
(SELECT DISTINCT E.SSN
FROM employee E, dependent D
WHERE E.Ssn = D.Essn)
----------------------------------------------------------------------------------------------------------------------------------------------------------
Query 7: List the names of managers who have at least one dependent.