Professional Documents
Culture Documents
Queries For Paractice ...
Queries For Paractice ...
--Create a report that displays the employee number, last name, and salary of all
employees
--who earn more than the average salary. Sort the results in ascending order by
salary
--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 u.
select employee_id,Last_name from employees where last_name in (select last_name
from employees where last_name like '%u%');
--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);
--displays the last name and salary of every employee who reports to King.
select last_name,salary from employees where manager_id =(select employee_id from
employees where last_name ='King');
-- list of department IDs for departments that do not contain the job ID
ST_CLERK.
--List the Empno, Ename, Sal, Daily sal of all emps in the asc order of Annsal
select employee_id,first_name,salary ,salary/30,12*salary annual from employees;
--List the total information of EMP table along with DNAME and emps Working Under
�ACCOUNTING�.
select e.*,d.department_name from employees e join departments d
on(e.department_id=d.department_id)
where department_name In (select department_name from departments where
department_name ='Accounting');
select * from employees where salary In (select max(salary) from employees where
department_id In(select department_id from departments where department_name
='Sales'));
-- List the department,details where at least two emps are working //display
department having two employees
select department_id ,count(*) from employees group by department_id having
count(*) = 2;
---display department_name of those having 2 employees
select department_name,count(*) from employees e join departments d on
(d.department_id=e.department_id) group by d.department_name, e.department_id
having count(*)= 2;
--department_name and no of employees in the departments
select department_name ,count(*) from employees e join departments d
on(d.department_id=e.department_id) group by d.department_name;
-- List the details of the department where maximum number of employees are
working.
select * from departments where department_id in (select department_id from
employees group by department_id
having count(*) in (select max(count(*)) from employees group by department_id) );
-- List the emps whose sal is greater than his managers salary
select a.first_name as manager,b.last_name from employees a,employees b where
b.employee_id = a.manager_id and a.salary >b.salary;
-- Name, Job and Salary of the emps who are not belonging to the department 10
but who have the same job and Salary as the emps of dept 10
--select first_name,salary,job_id from employees where department_id != 100
-- and
--job_id in (select job_id from employees where department_id = 100)
-- and salary in (select salary from employees where department_id = 100);
--union example
--retun matching values only
select department_id,manager_id from employees
union
select department_id,manager_id from departments;
--union all
--return all matched and unmatched values //join the records having same datatype
select department_id,manager_id from employees
union all
select department_id,location_id from departments;
select manager_id from employees --reutrn maching value only those which are
unique in only first table
minus
select manager_id from departments;