You are on page 1of 8

Name: Muheeb ur Rehman

SAP ID: 29640

DBS Lab [04]

1. Display the report of all those employees whose income is less than those who
work in department numbers 50, 20, and 10.

select first_name, department_id, salary from employees

where salary<(select avg(salary) from employees

where department_id in (50,20,10));


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 department_id from employees

where last_name like '%a%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.

select last_name, department_id, job_id from employees

where department_id in (select(department_id) from departments

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 from employees

where salary>(select max(salary) from employees

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 employee_id;
6. Display all the departments that have a minimum salary greater than that of
department 50.

select department_id, min(salary) from employees

group by department_id

having min(salary)>(select min(salary) from employees

where department_id=50);
Examples:
1. Which employees salary greater than Jones salary?
SELECT last_name, salary
FROM employees WHERE salary > (SELECT salary FROM employees WHERE
last_name = 'Jones');

2. 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);
3. 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);

4. Operator Example
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary < ANY (SELECT salary FROM employees WHERE job_id =
'IT_PROG')
5. Operator Example
SELECT employee_id, last_name, job_id, salary
FROM employees
WHERE salary < ALL (SELECT salary FROM employees WHERE job_id =
'IT_PROG')

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

8. Use of STDDEV operator


Select stddev(SALARY) , AVG(SALARY)
From employees;

You might also like