SQL Queries: Create The Following Tables
SQL Queries: Create The Following Tables
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 MIDDLE_ MANAGER_
LAST_NAME FIRST_NAME JOB_ID HIREDATE SALARY CO
_ID NAME ID
7369 SMITH JOHN Q 667 7902 17-DEC-84 800 NU
Where Conditions:
10. List out the employees who are earning salary between
3000 and 4500
11. List out the employees who are working in department 10
or 20
12. Find out the employees who are not working in department
10 or 30
13. List out the employees whose name starts with “S”
14. List out the employees whose name start with “S” and
end with “H”
17. list out the employees who are not receiving commission.
Order By Clause:
18. List out the employee id, last name in ascending order
based on the employee id.
Sub-Queries
JOINS
Simple join
Self Join:
42. Display the employee details with their manager names.
43. Display the employee details who earn more than their
managers salaries.
44. Show the no. of employees working under every
manager.
Outer Join:
34. SQL > Select employee_id, last_name, name from employee e, department d where
e.department_id=d.department_id
35. SQL > Select employee_id, last_name, function from employee e, job j where
e.job_id=j.job_id
36. SQL > 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
37. SQL > Select name, count(*) from employee e, department d where
d.department_id=e.department_id group by name
38. SQL > Select name, count(*) from employee e, department d where
d.department_id=e.department_id group by name having name=’SALES’
39. SQL > Select name, count(*) from employee e, department d where
d.department_id=e.department_id group by name having count (*)>=5 order by
name
40. SQL > Select function, count(*) from employee e, job j where j.job_id=e.job_id
group by function
41. SQL > 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
42. SQL > Select e.last_nameemp_name, m.last_name, mgr_name from employee e,
employee m where e.manager_id=m.employee_id
43. SQL > Select e.last_nameemp_name, e.salaryemp_salary, m.last_name,
mgr_name, m.salarymgr_salary from employee e, employee m where
e.manager_id=m.employee_id and m.salary
44. SQL > Select m.manager_id, count(*) from employee e, employee m where
e.emSployee_id=m.manager_id group by m.manager_id
45. SQL > Select last_name, d.department_id, d.name from employee e, department d
where e.department_id(+)=d.department_id
46. SQL > 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’))