Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

select * from employees ;

select * from departments;

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

select employee_id,last_name,salary from employees where salary >(select


avg(salary) from employees) 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.

-- // select department_id from departments where department_id <> (select


department_id from employees where job_id = 'ST_CLERK');
select department_id from departments
minus
select department_id from employees where job_id = 'ST_CLERK';

--last name dept id and department name having no employee


select last_name,department_id ,TO_CHAR(null) from employees
union
select TO_CHAR(null),department_id,department_name from departments;

--display unique jobs from employee table


select distinct job_id from employees;

--display the manager names


select first_name as managers from employees where employee_id in(select
manager_id from employees );

--List the emps who joined before 2007.


select * from employees where hire_date < ('02-jan-2007');

select * from employees ;

--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 Empno, Ename, working for Mgr 10


select employee_id,first_name,salary from employees where manager_id =100;

--Display the details of Steven


select * from employees where first_name ='Steven';

select * from employees;


select * from departments;

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

-- Find the highest paid employee of sales department.


-- select department_id from departments where department_name = 'Sales'; d

select * from employees where salary In (select max(salary) from employees where
department_id In(select department_id from departments where department_name
='Sales'));

--total salary given to manager


select sum(salary) from employees where employee_id in(select manager_id from
employees);

--q3--return no of employees and manager name


select b.First_name ,count(a.employee_id) from employees a,employees b where
a.manager_id = b.employee_id group by b.first_name;

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

--q2--department_name,no of employees and thier manager name


select first_name as Managers,department_name ,count(*) Total_employees from
employees e join departments d on(d.department_id=e.department_id)
where employee_id in(select manager_id from employees) group by d.department_name
,e.first_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) );

--department_name having max no of employees


select d.department_id,d.department_name,count(*) from employees e ,departments d

where e.department_id = d.department_id group by


d.department_id,d.department_name
having count(*) = (select max(count(*) ) from employees group by
department_id);
--not in query
select * from employees where department_id not in (select department_id from
departments where department_name = 'Sales');

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

select * from employees;


--- List the emp whose sal<his manager but more than any other manager.
select * from employees w,employees m
where w.manager_id = m.employee_id
and w.salary < m.salary
and w.salary > any (select salary from employees where employee_id in (select
manager_id from employees));

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

-- List the employees who are senior to their own manager.


select * from employees a,employees b where a.employee_id=b.manager_id and
a.Hire_date>b.Hire_date;

--manager who are senior to Shanta and junior to steven


--select manager_id from employees where hire_date<(select hire_date from
employees where last_name = 'Smith' )
-- and
--hire_date > (select hire_date from employees where last_name = '') ;

select * from employees ;

--highest paid employee working under vollman


select * from employees where salary in (select max(salary)
from employees where manager_id in (select employee_id from employees where
last_name = 'Vollman'));

--employees working under vollman


select first_name from employees where manager_id in (select employee_id from
employees where last_name ='Vollman');

--employees working under vollman and their salary


select first_name,salary from employees where manager_id in (select employee_id
from employees where last_name ='Vollman');

--employee working under king


select first_name,salary from employees where manager_id in (select employee_id
from employees where last_name ='King');

--manager names and employee names


SELECT E.first_name AS "Employee Name",
M.first_name AS "Manager"
FROM employees E
JOIN employees M
ON E.manager_id = M.employee_id;

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


union all
select department_id,manager_id from departments;

--select count(manager_id) from employees; 106


-- select count(manager_id) from departments; 11
-- select count(department_id) from employees; 106
-- select count(manager_id) from departments; 11
---select count(location_id) from departments; 26

select department_id,manager_id from employees


union
select department_id,location_id from departments;

select manager_id from employees


intersect
select manager_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;

--select location_id from departments


--minus
--select manager_id from departments

-- select manager_id from departments 11-26 error


-- minus
-- select location_id from departments

select first_name from employees


minus
select department_name from departments;

--detail of employee having max avg salary


select * from employees
where department_id in (select department_id from employees e having avg(salary)
=(select max(avg(salary)) from employees group by department_id) group by
department_id);

You might also like