Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

TASK # 04

[DATABASE – LAB]

NAME: ZAIN UL ABIDEEN


SAP: 35515
SECTION: CS4-1
INSTRUSTOR: QAZI SHUJA-UDDIN

DATED: 31-MARCH-2023
DATABASE

Example
Q.
SELECT last_name, salary
FROM employees
WHERE salary >
(SELECT salary
FROM employees
WHERE last_name = 'Jones');

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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);

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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);

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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);

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

Any operator example


SELECT employee_id, last_name, job_id, salary
FROM employees WHERE salary < ANY (SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')

All operator Example


SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary < ALL (SELECT salary
FROM employees WHERE job_id = 'IT_PROG')

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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);

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

Q. Display all the departments that have a minimum salary greater than that of department 20.

SELECT department_id, MIN(salary)


FROM Employees
GROUP BY department_id
HAVING MIN (salary)>
(SELECT MIN (salary)
FROM employees
WHERE department_id=20)

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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));

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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’.

SELECT employee_id, last_name


FROM employees
where department_id IN (
select DISTINCT department_id
from employees
where last_name like '%a%' AND last_name like '%u%');

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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.

select last_name,department_id ,job_id


from employees
where department_id in (
select department_id
from departments

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

where location_id =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');

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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;

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

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');

RIPHAH INTERNATIONAL UNIVERSITY


DATABASE

---------------------------------------------------------------------------------------------------------------------

RIPHAH INTERNATIONAL UNIVERSITY

You might also like