Database Lab Tasks
Database Lab Tasks
[DATABASE – LAB]
DATED: 31-MARCH-2023
DATABASE
Example
Q.
SELECT last_name, salary
FROM employees
WHERE salary >
(SELECT salary
FROM employees
WHERE last_name = 'Jones');
Task 1
Display all employees name whose salary is equal to empoyeed_id 143.
SELECT First_name, salary
FROM employees
WHERE salary >
(SELECT salary
FROM employees
WHERE employee_id = 143);
Q. Display the employees first name ,job id whose job title is the same as that of employee 177.
Select first_name,job_id
From employees
Where job_id=(select job_id From employees
Where employee_id=177);
Q. Display all employee records whose job title is the same as that of employee 141 and whose salary is greater
than that of employee 143.
SELECT *
FROM employees
WHERE job_id =
(SELECT job_id
FROM employees
WHERE employee_id = 141)
AND salary >
(SELECT salary
FROM employees
WHERE employee_id = 143);
Q.Display the employee name, job title and salary of all employees whose salary is equal to the minimum salary.
SELECT last_name, job_id, salary
FROM employees
WHERE salary = (SELECT MIN(salary)
FROM employees);
Q. Display all the departments that have a minimum salary greater than that of department 20.
LAB TASKS
1. Display the report of all those employees whose income is less than those who work in department numbers
50, 20, and 10.
select *
from employees
where salary <any (select salary
from employees
where department_id in (10,20,50));
2. Write a query that displays the employee number and last name of all employees who work in a
department with any employee whose last name contains ‘a’ and ‘u’.
3. The HR department needs a report that displays the last name, department number, and job ID of all
employees whose department location ID is 1700.
4. Display the job number and job title of those employees whose maximum salary is greater than 'ST_MAN'
select job_id,job_title
from jobs
where max_salary>(select max_salary
from jobs
where job_id='ST_MAN');
5. Show a report that displays the employee number, first name, and salary of all employees who earn more
than the average salary. Sort the results according to salary in ascending order.
select employee_id,first_name,salary
from employees
where salary>(select avg(salary)
from employees)
order by salary asc;
6. Display all the departments that have a minimum salary greater than that of department 50
select department_id,min(salary) as min_salary
from employees
group by department_ID
having min(salary)>(
select min(salary)
from employees
where department_id = '50');
---------------------------------------------------------------------------------------------------------------------