Database lab work
Database lab work
Section: BCS-3A
LAB TASK 1
Write a SQL statement that uses subquery to display the last name and hire date of any employee in the
same department as the employee whose last name is provided by the user For example, if the user enters
Zlotkey, find all employees who work with Zlotkey (excluding Zlotkey).
QUERY:
SELECT last_name,hire_date
FROM employees
WHERE department_id = (
SELECT department_id
FROM employees
Write a SQL statement that uses subquery to display the employee number, last name, and salary of all
employees who earn more than the average salary. Sort the results in order of ascending salary..
QUERY:
FROM employees
SELECT AVG(salary)
FROM employees
OUTPUT:
Lab Task 3
Write a SQL statement that uses subquery to display the department number, last name, and job ID for
QUERY:
FROM employees
WHERE department_id = (
SELECT department_id
FROM departments
);
OUTPUT:
LAB TASK 4
Write a SQL statement that uses subquery to find those departments where maximum salary is 7000 and
above. The employees worked in those departments have already completed one or more jobs. Return all
QUERY:
SELECT *
FROM departments
WHERE department_id IN (
SELECT department_id
FROM employees
GROUP BY department_id
);
OUTPUT:
LAB TASK 5
Write a SQL statement that uses subquery to find those employees whose department is located in the city
'London'. Return first name, last name, salary, and department ID.
QUERY:
FROM employees
WHERE department_id IN (
SELECT department_id
FROM departments
WHERE location_id = (
SELECT location_id
FROM locations
);
OUTPUT:
LAB TASK 6
Write a SQL statement that uses subquery to display the last name and salary of every employee who
reports to King.
QUERY:
FROM employees
WHERE manager_id = (
SELECT employee_id
FROM employees
);
OUTPUT: