You are on page 1of 3

practicale 6 3-10-15

1) Write a query to find the names (first_name, last_name) and salaries of the e
mployees who have higher salary than the employee whose last_name='Bull'.
==> select first_name,last_name,salary from employees where salary>(select salar
y from employees where last_name='BULL');
2) Find the names (first_name, last_name) of all employees who work in the IT de
partment.
==> select first_name,last_name from employees where DEPARTMENT_ID IN (select DE
PARTMENT_ID from DEPARTMENTS where DEPARTMENT_name='IT');
3) Find the names (first_name, last_name) of the employees who have a manager wh
o works for a department based in United States
==> select first_name,last_name from EMPLOYEES where MANAGER_id in(select EMPLOY
EE_id from EMPLOYEES where DEPARTMENT_id in(select department_id from department
s where location_id in(select location_id from locations where country_id='US'))
);
4) Find the names (first_name, last_name) of the employees who are managers
==> select first_name,last_name from employees where (employee_id IN (select MAN
AGER_ID from employees));
5) Find the names (first_name, last_name), salary of the employees whose salary
is greater than the average salary
==> select first_name,last_name from employees where salary>(select avg(salary)
from employees);
6) Find the names (first_name, last_name), salary of the employees whose salary
is
equal to the minimum salary for their job grade
==> select first_name,last_name,salary from employees,jobs where employees.salar
y=jobs.min_salary and employees.job_id=jobs.job_id;
7) Find the names (first_name, last_name), salary of the employees who earn more
than
the average salary and who works in any of the IT departments.
==> select first_name,last_name from employees,departments where salary>(select
avg(salary) from employees) and employees.department_id=departments.department_i
d and departments.department_name='IT';
8) Find the names (first_name, last_name), salary of the employees who earn more
than
Mr. Bell.
==> select first_name,last_name from employees where salary>(select salary from
employees where last_name='BELL');
9) Find the names (first_name, last_name), salary of the employees who earn the
same
salary as the minimum salary for all departments.
==> select first_name,last_name,salary from employees,departments,jobs where emp
loyees.salary=jobs.min_salary and employees.department_id=departments.department

_id;
10) Find the names (first_name, last_name), salary of the employees whose salary
greater than average salary of all department.
==> select first_name,last_name,salary from employees where salary>(select avg(s
alary) from employees where department_id in(select department_id from employees
));
11) Write a query to find the names (first_name, last_name) and salary of the
employees who earn a salary that is higher than the salary of all the Shipping C
lerk
(JOB_ID = 'SH_CLERK'). Sort the results on salary from the lowest to highest.
==> select first_name,last_name,salary from employees where salary>(select max(s
alary) from employees where job_id='SH_CLERK') order by salary;
12) Write a query to find the names (first_name, last_name) of the employees who
are
not supervisors.
==> select first_name,last_name from employees where job_id in(select job_id fro
m jobs where job_title!='supervisors');
13) Write a query to display the employee ID, first name, last names, and depart
ment
names of all employees.
==> select employee_id,first_name,last_name,departments.department_name from emp
loyees,departments where departments.department_id=employees.department_id;
14) Write a query to display the employee ID, first name, last names, salary of
all
employees whose salary is above average for their departments.
==> SELECT employee_id, first_name,last_name,salary FROM employees WHERE salary
> ( SELECT AVG(salary) FROM employees WHERE department_id = employees.department
_id);
15) Write a query to fetch even numbered records from employees table.
==> select * from (select employee_id,rownum rn from employees ) where mod (rn
, 2) != 0;
16) Last update on May 30 2015 12:34:59 (UTC/GMT +8 hours)
==>
17) Write a query to find the 4th minimum salary in the employees table.
==> SELECT DISTINCT salary FROM employees e1 WHERE 4 = (SELECT COUNT(DISTINCT sa
lary) FROM employees e2 WHERE e1.salary >= e2.salary);
18) Write a query to select last 10 records from a table.
==> SELECT * FROM (SELECT * FROM employees ORDER BY employee_id DESC LIMIT 10) s
ub ORDER BY employee_id ASC;
19) Write a query to list department number, name for all the departments in whi
ch

there are no employees in the department.


==> SELECT * FROM departments WHERE department_id NOT IN (select department_id F
ROM employees);
20) Write a query to get 3 maximum salaries.
==> SELECT DISTINCT salary FROM employees a WHERE 3 >= (SELECT COUNT(DISTINCT s
alary) FROM employees b WHERE a.salary <= b.salary) ORDER BY a.salary ASC;
21) Write a query to get 3 minimum salaries.
==> SELECT DISTINCT salary FROM employees a WHERE 3 >= (SELECT COUNT(DISTINCT s
alary) FROM employees b WHERE a.salary >= b.salary) ORDER BY a.salary DESC;
22) Write a query to get nth max salaries of employees.
==> SELECT salary FROM employees emp1 WHERE (1) = ( SELECT COUNT(DISTINCT(emp2.s
alary)) FROM employees emp2 WHERE emp2.salary > emp1.salary);
==> select salary from employees where salary in(select max(salary) from employe
es);

You might also like