sql statement oracle database Exercise 1
// 1. Employees table all the data query
select * from employees
// 2. All printing company manager_id
the SELECT manager_id from the Employees
// 3 employees email query full name, company email in a unified "@ zpark.cn " the end of
the SELECT email || '@ zpark.cn '
AS email
from the Employees;
// 4 according to the old entry date arranged by the New employee information
the SELECT hire_date
from the Employees
the Order by hire_date desc;
5 // Query No. 80 departments of all employees
select department_id from employees where department_id = 80
6 // Query No. 50 sectors per person increase a person's name and salary of 1000 yuan after wages.
//普通方法1
select first_name,salary,salary+1000,department_id
from employees
where department_id=50;
//分组方法2
select first_name,salary,salary+1000,department_id
from employees
where department_id=50
group by first_name,salary,salary+1000,department_id;
7 // Query No. 80 sector wage greater than 7000 employees full name and salary.
select first_name,salary,department_id
from employees
where salary>7000 and department_id=80;
// 80 8 Queries sector wage greater than 8000 and a commission of 0.3 higher than the employee's name, salary and commission
the SELECT first_name, salary, salary * 0.3, department_id
from the Employees
the WHERE salary> 8000 and commission_pct> 0.30 and department_id = 80;
// 9 search jobs (job_id) for the 'AD_PRES' of wages
// fuzzy query conditions
select *from employees
select first_name,job_id,salary
from employees
where job_id like ‘AD_PRES’;
10 // Query commission (commission_pct) is 0 or NULL employee information
//is null ,is not null,or
select *
from employees
where commission_pct is null or commission_pct=0 ;
11 // query entry date information on all employees of between 1997-5-1 to 1997-12-31
// Zone Compare: between
select *
from employees
where to_char(hire_date,‘yyyy-MM-dd’)
between ‘1997-05-01’ and ‘1997-12-31’ ;
// 12 not to display the name of the employee details 'L' or contains employee information word 'SM' word
// fuzzy query conditions
select *
from employees
where first_name not like ‘%l%’ or first_name like ‘%sm%’;
13 // Query the telephone number information to all employees starting with 5.
// fuzzy query
select *
from employees
where phone_number like ‘5%’;
14 // Query last_name all employee information to the end of the 80 departments of the n
select *
from employees
where department_id=80 and last_name like ‘%n’;
15 // query employee information for all last_name consists of four or more letters
select *
from employees
where last_name like ‘%____%’;
// line function exercises
// a row hire_date seen as employee birthdays, birthday this month inquiry staff (visits knowledge: one-way function)
select *
from employees
where to_char(hire_date,‘mm’) = 04;
// 2 query the second half of 2002 recruits (study knowledge: one-way function)
the SELECT *
from the Employees
the WHERE the TO_CHAR (hire_date, 'yyyy-MM')> '2002-06';
// 3 print that he was born a few days
select sysdate-to_date ( '1996-09-30' , 'yyyy-MM-dd') from dual;
// 4. Print entry time for more than 30 years of employee information
select *
from employees
where to_char(sysdate,‘yyyy’)-to_char(hire_date,‘yyyy’)>=30;
// set of functions Exercise
// 1. Display the minimum wage (set of functions) of various positions
select job_id,min(salary)
from employees
group by job_id;
// 2 The number of employees each month in 1997 seeking the entry of the. (Study knowledge: group function)
select to_char(hire_date,‘MM’),count(*)
from employees
where to_char(hire_date,‘yyyy’)=‘1997’
group by to_char(hire_date,‘MM’);
// 3 queries for each department, the highest salary for each position (visits knowledge: grouping)
the SELECT department_id, job_id, max (salary)
from the Employees
Group by department_id, job_id;
4 // Query the total salary for each department
the SELECT department_id, SUM (salary)
from the Employees
Group by department_id
// query 5, 50 departments, No. 60 departments, 70 departments of the average salary of
the SELECT department_id, AVG (salary)
from the Employees
the WHERE department_id or department_id = 50 = 60 = 70 or department_id
Group by department_id;
6 // Query the highest wage sectors of the minimum wage.
The SELECT department_id, max (salary), min (salary)
from the Employees
Group by department_id
// 7. The total number of staff positions each query.
select job_id,count(*)
from employees
group by job_id
// 8 query various departments in various positions of the average wage.
select department_id,job_id,avg(salary)
from employees
group by department_id,job_id