LOCATION
|
|
Location_ID
|
Regional_Group
|
122
|
NEW
YORK
|
123
|
DALLAS
|
124
|
CHICAGO
|
167
|
BOSTON
|
DEPARTMENT
|
||
Department_ID
|
Name
|
Location_ID
|
10
|
ACCOUNTING
|
122
|
20
|
RESEARCH
|
124
|
30
|
SALES
|
123
|
40
|
OPERATIONS
|
167
|
JOB
|
|
Job_ID
|
Function
|
667
|
CLERK
|
668
|
STAFF
|
669
|
ANALYST
|
670
|
SALESPERSON
|
671
|
MANAGER
|
672
|
PRESIDENT
|
EMPLOYEE
|
|||||||||
EMPLOYEE_ID
|
LAST_NAME
|
FIRST_NAME
|
MIDDLE_NAME
|
JOB_ID
|
MANAGER_ID
|
HIREDATE
|
SALARY
|
COMM
|
DEPARTMENT_ID
|
7369
|
SMITH
|
JOHN
|
Q
|
667
|
7902
|
17-DEC-84
|
800
|
NULL
|
20
|
7499
|
ALLEN
|
KEVIN
|
J
|
670
|
7698
|
20-FEB-85
|
1600
|
300
|
30
|
7505
|
DOYLE
|
JEAN
|
K
|
671
|
7839
|
04-APR-85
|
2850
|
NULL
|
30
|
7506
|
DENNIS
|
LYNN
|
S
|
671
|
7839
|
15-MAY-85
|
2750
|
NULL
|
30
|
7507
|
BAKER
|
LESLIE
|
D
|
671
|
7839
|
10-JUN-85
|
2200
|
NULL
|
40
|
7521
|
WARK
|
CYNTHIA
|
D
|
670
|
7698
|
22-FEB-85
|
1250
|
500
|
30
|
- List all the
employee details
- List all the
department details
- List all job
details
- List all the
locations
- List out
first name,last name,salary, commission for all employees
- List out
employee_id,last name,department id for all employees and rename employee id as
“ID of the employee”, last name as
“Name of the employee”, department id as
“department ID”
- List out the
employees anuual salary with their names only.
- List the
details about “SMITH”
- List out the
employees who are working in department 20
- List out the
employees who are earning salary between 3000 and 4500
- List out the
employees who are working in department 10 or 20
- Find out the
employees who are not working in department 10 or 30
- List out the
employees whose name starts with “S”
- List out the
employees whose name start with “S” and end with “H”
- List out the
employees whose name length is 4 and start with “S”
- List out the
employees who are working in department 10 and draw the salaries more than
3500
- list out the
employees who are not receiving commission.
- List out the
employee id, last name in ascending order based on the employee id.
- List out the
employee id, name in descending order based on salary column
- list out the
employee details according to their last_name in ascending order and
salaries in descending order
- list out the
employee details according to their last_name in ascending order and then
on department_id in descending order.
- How many
employees who are working in different departments wise in the
organization
- List out the
department wise maximum salary, minimum salary, average salary of the
employees
- List out the
job wise maximum salary, minimum salary, average salaries of the
employees.
- List out the
no.of employees joined in every month in ascending order.
- List out the
no.of employees for each month and year, in the ascending order based on
the year, month.
- List out the
department id having at least four employees.
- How many
employees in January month.
- How many
employees who are joined in January or September month.
- How many
employees who are joined in 1985.
- How many
employees joined each month in 1985.
- How many
employees who are joined in March 1985.
- Which is the
department id, having greater than or equal to 3 employees joined in April
1985.
Sub-Queries
- Display the
employee who got the maximum salary.
- Display the
employees who are working in Sales department
- Display the
employees who are working as “Clerk”.
- Display the
employees who are working in “New York”
- Find out
no.of employees working in “Sales” department.
- Update the
employees salaries, who are working as Clerk on the basis of 10%.
- Delete the
employees who are working in accounting department.
- Display the
second highest salary drawing employee details.
- Display the
Nth highest salary drawing employee details
- List out the
employees who earn more than every employee in department 30.
- List out the
employees who earn more than the lowest salary in department 30.
- Find out
whose department has not employees.
- Find out
which department does not have any employees.
Joins
Simple join
- Select * from employee;
- Select * from department;
- Select * from job;
- Select * from loc;
- Select first_name, last_name, salary,
commission from employee;
- Select employee_id “id of the employee”,
last_name “name", department id as “department id” from employee;
- Select last_name, salary*12 “annual
salary” from employee
- Select * from employee where
last_name=’SMITH’;
- Select * from employee where
department_id=20
- Select * from employee where salary
between 3000 and 4500
- Select * from employee where
department_id in (20,30)
- Select last_name, salary, commission,
department_id from employee where department_id not in (10,30)
- Select * from employee where last_name
like ‘S%’
- Select * from employee where last_name
like ‘S%H’
- Select * from employee where last_name
like ‘S___’
- Select * from employee where
department_id=10 and salary>3500
- Select * from employee where commission
is Null
- Select employee_id, last_name from employee
order by employee_id
- Select employee_id, last_name, salary
from employee order by salary desc
- Select employee_id, last_name, salary
from employee order by last_name, salary desc
- Select employee_id, last_name, salary
from employee order by last_name, department_id desc
- Select department_id, count(*), from
employee group by department_id
- Select department_id, count(*),
max(salary), min(salary), avg(salary) from employee group by department_id
- Select job_id, count(*), max(salary),
min(salary), avg(salary) from employee group by job_id
- select datepart(mm,hire_date)
month,count(*) from employee
- select datepart(yy,hire_date)
year,datepart(mm,hire_date) month,count(*) from employee group by
datepart(yy,hire_date) ,datepart(mm,hire_date) order by year
- Select department_id, count(*) from
employee group by department_id having count(*)>=4
- select datename(mm,hire_date)
month,count(*) NoOfEmployees from employee group by datename(mm,hire_date)
having datename(mm,hire_date)='January'
- select datename(mm,hire_date)
month,count(*) NoOfEmployees from employee group by datename(mm,hire_date)
having datename(mm,hire_date) in ('January','September')
- select datename(yy,hire_date)
year,count(*) NoOfEmployees from employee
- Select datepart(yy,hire_date)Year,
datepart(mm,hire_date) Month, count(*) [No. of employees] from employee
where datepart(yy,hire_date)=1985
- Select datepart(yy,hire_date) Year,
datename(mm,hire_date) Month,
- Select department_id, count(*)
[No. of employees] from employee
- Select * from employee where
salary=(select max(salary) from employee)
- Select * from employee where
department_id IN (select department_id from department where name=’SALES’)
- Select * from employee where job_id in
(select job_id from job where function=’CLERK’
- Select * from employee where department_id=(select
department_id from department where location_id=(select location_id from
location where regional_group=’New York’))
- Select * from employee where
department_id=(select department_id from department where name=’SALES’
group by department_id)
- Update employee set salary=salary*10/100
where job_id=(select job_id from job where function=’CLERK’)
- delete from employee where
department_id=(select department_id from department where
name=’ACCOUNTING’)
- Select * from employee where
salary=(select max(salary) from employee where salary <(select
max(salary) from employee))
- Select distinct e.salary from employee
where & no-1=(select count(distinct salary) from employee where
sal>e.salary)
- Select * from employee where salary >
all (Select salary from employee where department_id=30)
- Select * from employee where salary >
any (Select salary from employee where department_id=30)
- Select employee_id, last_name,
department_id from employee e where not exists (select department_id from
department d where d.department_id=e.department_id)
- Select name from department d where not
exists (select last_name from employee e where
d.department_id=e.department_id)
- Select employee_id, last_name, salary,
department_id from employee e where salary > (select avg(salary) from
employee where department_id=e.department_id)
- Select employee_id, last_name, name from
employee e, department d where e.department_id=d.department_id
- Select employee_id, last_name, function
from employee e, job j where e.job_id=j.job_id
- Select employee_id, last_name, name,
regional_group from employee e, department d, location l where
e.department_id=d.department_id and d.location_id=l.location_id
- Select name, count(*) from employee e,
department d where d.department_id=e.department_id group by name
- Select name, count(*) from employee e,
department d where d.department_id=e.department_id group by name having
name=’SALES’
- Select name, count(*) from employee e,
department d where d.department_id=e.department_id group by name having
count (*)>=5 order by name
- Select function, count(*) from employee
e, job j where j.job_id=e.job_id group by function
- Select regional_group, count(*) from
employee e, department d, location l where e.department_id=d.department_id
and d.location_id=l.location_id and regional_group=’NEW YORK’ group by
regional_group
- Select employee_id, last_name, grade_id
from employee e, salary_grade s where salary between lower_bound and
upper_bound order by last_name
- Select grade_id, count(*) from employee
e, salary_grade s where salary between lower_bound and upper_bound group
by grade_id order by grade_id desc
- Select grade_id, count(*) from employee
e, salary_grade s where salary between lower_bound and upper_bound and
lower_bound>=2000 and lower_bound<=5000 group by grade_id order by
grade_id desc
- Select e.last_name emp_name, m.last_name,
mgr_name from employee e, employee m where e.manager_id=m.employee_id
- Select e.last_name emp_name, e.salary
emp_salary, m.last_name, mgr_name, m.salary mgr_salary from employee e,
employee m where e.manager_id=m.employee_id and m.salary
- Select last_name, d.department_id, d.name
from employee e, department d where e.department_id*=d.department_id and
d.department_idin (select department_id from department where name IN
(‘SALES’,’OPERATIONS’))
- Select function from job where job_id in
(Select job_id from employee where department_id=(select department_id
from department where name=’SALES’)) union Select function from job where
job_id in (Select job_id from employee where department_id=(select
department_id from department where name=’ACCOUNTING’))
- Select function from job where job_id in
(Select job_id from employee where department_id=(select department_id
from department where name=’SALES’)) union all Select function from job
where job_id in (Select job_id from employee where department_id=(select
department_id from department where name=’ACCOUNTING’))
- Select function from job where job_id in
(Select job_id from employee where department_id=(select department_id
from department where name=’RESEARCH’)) intersect Select function from job
where job_id in (Select job_id from employee where department_id=(select
department_id from department where name=’ACCOUNTING’)) order by function
No comments:
Post a Comment