Query on Oracle-HR table

1. Find all the contents of the entire employee table.

select *
from employees

2. View the employee's name (last_name).

select last_name
from employees;

3. Check the employee number, name and type of work.

select last_name,job_id,employee_id
from employees;

4. Display the names and salaries of all employees and display DEPARTMENT_ID as (Department_Id).

select last_name,salary,DEPARTMENT_ID as Department_Id
from employees;

5. Find employees who work in department 60.

select last_name+first_name name,department_id
from employees
where departmet_id=60;

6. It is required to find the names (last_name) of employees whose positions are SH_CLERK and SA_MAN.

select last_name job_id
from employees
where job_id in ('sh_clerk','sa_man');

7. Find the type and name of employees whose positions are not SH_CLERK and SA_MAN. Display the name as (first_name+last_name named "Name").

select first_name+last_name Name, job_id
from employees
where job_id not in ('sh_clerk','sa_man');

8. Find out which employees have a salary between 2000 and 3000

select *
from employees
where salary between 2000 and 3000

9. Find out which employees are not paid between 3000 and 5000

select *
from employees
where salary not between 3000 and 5000

10. Find employee information whose first_name starts with D and only three letters later.

select *
from employees
where first_name like ‘D___' and first_name not like ‘d__ ‘

11. Find the employee information whose last_name starts with K.

select last_name,first_name,department_id
from employees
where last_name like ‘k%'

12. Find the employee's name (First_name), job type and department number whose name starts with the letter M and ends with l, and the third letter is c

select first_name,job_id,department_id
from employees
where first_name like ‘m_c%l'

13. Find out which employees whose job name does not start with SA.

select job_id
from employees
where job_id not like 'sa%'

14. Find information about employees who have no bonuses.

select *
from employees
where commission_pct is null

15. Find information about employees with bonuses.

select *
from employees
where commission_pct is not null

16. Find the information of employees who are not CLERK in Department 30.

select *
from employees
where department_id=30 and job_id not like ‘%clerk%'

17. Find information about employees who work in department 30 or who are not CLERK.

select *
from employees
where department_id=30
or job_id not like ‘%clerk%'

18. Find the information of employees whose salary is greater than 5000 in department 60

select *
from employees
where department_id=60
and salary>5000

19. Display the employee's name (last_name) in alphabetical order.

select last_name
from employees
order by last_name

20. Display in descending order of department number.

select * 
from employees 
order by department_id desc

21. Find the information of employees whose salary is higher than $2000, sort by department number and employee name.

select * from employees where salary>2000 order by department_id,employee_id

22. Select employee information with bonuses higher than 5%

SELECT FIRST_NAME, LAST_NAME, COMMISSION_PCT
FROM dbo.EMPLOYEES
WHERE (COMMISSION_PCT > .05)

23. Query information about employees whose annual salary is higher than 50,000

select * from employees where 12*salary>50000

24. Query the name of the employee whose area code is 1700

select first_name,last_name,city,department.location_id
from locations,employees,department
where locations.location_id=department.location_id
and locations.location_id=1700

25. Query the name and salary information of employees whose work area is Beijing

select first_name,last_name,salary,commission_pct,city
from locations,employees,departments
where departments.location_id=locations.location_id
and departments.department_id = employees.department_id
and departments.location_id=1700

26. Query the name of the employee whose salary standard is Type B, the employee salary and the name of the salary category

select last_name,first_name,salary,commission_pct,gra
from departments d,employees e,job_grades j
where e.salary between j.lowest and j.highest
and j.gra='b'
and d.department_id=e.department_id

27. Query the employee and salary information managed by the supervisor Raphaely

select a.last_name+a.first_name as name, a.salary,a.commission_pct,b.last_name
from employees a,employees b
where a.department_id=b.department_id
and a.last_name like ‘%raphaely%'

28. Find out the department where the employee is located, and display the records of the department where there are no employees.

select e.last_name+e.first_name as name,d.department_id
from departments d
left outer join employees e
on (e.department_id=d.department_id)

29. Query the information of employees who are not assigned to the department

select e.last_name+e.first_name as name,e.department_id
from departments d
left outer join employees e
on (e.department_id=d.department_id)
where d.department_id is null

30. Calculate the average salary and the total salary of each department

select department_id,sum (salary) sum,avg (salary) avg
from employees
group by department_id

31. Query the number of employees of each type of work in each department

select count(*)num,department_id,job_id
from employees
group by department_id,job_id

32. Please calculate the total number of employees in the employee table

select count(*)
from employee

33. Please calculate the average salary of all employees in the employee table

select avg(salary)
from employee

34. Please query the minimum wage in the employee table

select min(salary)
from employee

35. Please query the highest salary in the employee table

select max(salary)
from employee

36. Please calculate the average salary, maximum salary and minimum salary of each department

select max(salary) max,min(salary) min,avg(salary) avg,department_id
from employee
group by department_id

37. Query the department name, salary and salary grouped by department name whose total salary is greater than 4200

select department_name,sum(salary)
from employees e,departments d
where e.department_id=d.department_id
group by department_name
having sum(salary)>4200
test001

38. Please query the employees with the minimum wage in the employee table

select last_name
from employee
where salary=(select min(salary) from employee)

39. Please query the employee with the highest salary in the employee table

select last_name
from employee
where salary=(select max(salary) from employee)

40. Query the situation of employees whose salary is higher than the last_name of employee No. 105 and whose job type is the same as him.

select last_name,job_id,salary
from employees
where salary>(select salary from employees where employee_id='105′)
and job_id=(select job_id from employees where employee_id='105′)

41. Query employees whose wages are higher than or equal to the highest wage in department 30.

select last_name,salary
from employees
where salary>=(select max(salary) from employees where department_id=30)

42. Query the information of all personnel in the department of employees whose salary is between 1,000 and 5,000.

select *
from employees
where department_id in
(select department_id from employees where salary between 1000 and 5000)

43. Find the information of all employees whose salary is higher than that of department No. 60. Display its employee number, last_name and salary.

select last_name,employee_id,salary
from employees
where salary>
(select max(salary) from employees where department_id=60)

Guess you like

Origin blog.csdn.net/qq_41186565/article/details/104780063