sql statement oracle database paging query on exercises

sql statement oracle database paging query on exercises

  1. Queries maximum wage of three employee information

select *
from (select * from employees
order by salary desc
)
where rownum<=3;

  1. Queries wages ranked No. 5 to No. 10 employee information

select * from
(select e.*,rownum r
from employees e
order by salary desc
)
where r between 5 and 10;

  1. Queries first_name is the third to fifth employee information at the beginning of a capital D

select * from
(select e.*,rownum r
from employees e
where first_name like ‘D%’
)
where r between 3 and 5 ;

Subqueries practice

  1. Show all wages higher than the 'Allan' (first_name) the names and salaries

select *
from employees
where salary > (select salary from employees where first_name = ‘Allan’);

  1. Details show the 'Allan' (first_name) employees doing the same work

select *
from employees
where job_id = (select job_id from employees where first_name = ‘Allan’);

  1. And No. 30 show the same department first_name 'Guy' wages and salaries of employees names and salaries

select *
from employees
where department_id=30 and
salary=(select salary from employees where first_name=‘Guy’);

  1. Discover all wages higher than the average wage (average wage, including all employees) sales staff ( 'SA_REP') (job_id)

select *
from employees
where job_id=‘SA_REP’ and
salary > (select avg(salary) from employees) ;

Table join queries practice

// query employee information the Employees
// Query department information the Departments
// query the location information of locations
the SELECT * from the Employees
the SELECT * from the Departments
the SELECT * from locations Manger

  1. Name displays the name and salary of all employees and their departments of

select e.first_name,salary,d.department_name r

from employees e inner join departments d state province

on e.department_id =d.department_id

  1. Queries in R & D ( 'IT') work of the staff number, name, department, job location

select e.first_name,e.manager_id,department_name r,l.street_address a

​ from employees e inner join departments d

​ on e.department_id=d.department_id and d.department_name=‘IT’

​ inner join locations l

​ on d.location_id = l.location_id;

  1. The name and number of employees of various departments query
    the SELECT d.department_name, COUNT (*)
    from the Employees E Inner the Join the Departments d
    ON e.department_id = d.department_id
    Group by d.department_name

  2. Query basic employee information, additional names of its superiors
    . The SELECT * E, e2.first_name
    from the Employees E, the WHERE e.manager_id the Employees e2 = e2.employee_id;

Guess you like

Origin blog.csdn.net/JiangLi_/article/details/90645234