- The employee's email query full name, company email unified with "@ zpark.cn" end
select email || '@ zpark.cn' from employees; - According to the old entry date employee information arranged by the New
select employee_id, first_name, last_name, email , phone_number, hire_date, job_id, salary, commission_pct, manager_id, department_id from employees order by hire_date; - Query No. 80 sector wage greater than 7000 employees full name and salary
select first_name || '' || last_name as name, salary from employees where department_id = 80 and salary> 7000; - All last_name employee information inquiry by the more than four-letter
select * from employees where last_name like ' ____%';
One-way function exercises
- The column hiredate seen as employee birthdays, birthday this month inquiry staff (visits knowledge: one-way function)
the SELECT * from the Employees the WHERE the TO_CHAR (hire_date, 'mm') = the TO_CHAR (sysdate, 'mm'); - Please contact 2002 recruits (study knowledge: one-way function) with three or more ways
①select * from the Employees the WHERE the TO_CHAR (hire_date, 'yyyy') = '2002';
②select * from the Employees the WHERE hire_date the BETWEEN to_date ( '2002 -1-1 ',' YYYY-mm-dd ') and TO_DATE (' 2002-12-30 ',' YYYY-mm-dd ');
③select from the Employees WHERE the hire_date *> = TO_DATE (' 2002-1-1 ',' yyyy-mm-dd ') and hire_date <= to_date (' 2002-12-30 ',' yyyy-mm-dd '); - Queries second half of 2002 recruits (study knowledge: one-way function)
the SELECT * from the Employees to_date the WHERE hire_date the BETWEEN ( '2002-7-1', 'yyyy-mm-dd') and to_date ( '2002-12-30 ',' yyyy-mm-dd '); - Print how many days he was born
select to_date (to_char (sysdate, ' yyyy-mm-dd'), 'yyyy-mm-dd') - to_date ( '1996-3-1', 'yyyy-mm-dd') from dual;
Group Functions practice
- Employee number (inspection knowledge: group function) seeking 1997 each month recruited a
select count (*), to_char ( hire_date, 'mm') from employees where to_char (hire_date, 'yyyy') = '2002' group by to_char (hire_date, 'mm') ; - Query No. 50 departments, 60 departments, 70 departments of the average salary
select avg (salary), department_id from employees where department_id in (50, 60, 70) group by department_id; - The highest average wage for the wage of 8,000 yuan higher than the sector
select max (salary), department_id from employees group by department_id having avg (salary)> 8000; - Statistics in the number of company managers
①select COUNT (COUNT (manager_id)), manager_id from the Employees manager_id the WHERE IS not null Group by manager_id;
②select COUNT (DISTINCT manager_id) from the Employees;
Paging query exercise
Queries wages ranked No. 5 to No. 10 employee information
select * from (select employee_id, first_name , rownum as rn from (select * from employees order by salary desc)) where rn> = 5 and rn <= 10;
Subqueries practice
- Queries salary greater than the average wage of employees in this sector basic information
select * from (select * from employees group by department_id having salary> avg (salary)); - Display with 30 departments first_name is 'Guy' wages the same employee names and salaries
select first_name, salary from employees where salary = (select salary from employees where department_id = 30 and first_name = 'Guy'); - The number of inquiries each employee wage jobs is greater than the average wage (average wage, including all staff) and staff positions
select count (*), job_id from employees where salary> (select avg (salary) from employees) group by job_id;
Table join queries practice
- Display the names of all employees and their departments the names and salaries
select employees.first_name, department_name, salary from employees left outer join departments on employees.department_id = departments.department_id; - Query number of employees working in research and development ( 'IT'), name, department, job location
select employees.employee_id, employees.first_name, employees.department_id from ( employees left outer join departments on employees.department_id = departments.department_id) left outer join locations on departments.location_id = locations.location_id - The name and number of employees of various departments inquiry
select departments.department_name, count (*) from employees left join departments on employees.department_id = departments.department_id group by departments.department_name; - Query basic employee information, additional names of its superior
select e1.employee_id, e1.first_name, e1.salary, e2.first_name from employees e1 left join employees e2 on e1.manager_id = e2.employee_id - Seeking the same entry date (same date) staff (visits knowledge: self-connection) (duplicate)
the SELECT e1.first_name, e2.first_name from the Employees E1 Inner ON e1.hire_date the Join the Employees e2 = e2.hire_date and E1. ! = e2.first_name FIRST_NAME
WHERE e1.employee_id <e2.employee_id; - (de-emphasis) - Shows the basic salary of each department manager
select employees.employee_id, salary from departments left outer join employees on departments.manager_id = employees.employee_id