oracle數據庫的sql語句練習1

oracle數據庫的sql語句練習1

//1. 查詢員工表所有數據
select * from employees

//2. 打印公司裏所有的manager_id
select manager_id from employees

//3. 查詢所員工的email全名,公司email 統一以 "@zpark.cn" 結尾
select email || ‘@ zpark.cn
as email
from employees;

//4. 按照入職日期由新到舊排列員工信息
select hire_date
from employees
order by hire_date desc;

//5. 查詢80號部門的所有員工
select department_id from employees where department_id = 80

//6. 查詢50號部門每人增長1000元工資之後的人員姓名及工資.

//普通方法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. 查詢80號部門工資大於7000的員工的全名與工資.

select first_name,salary,department_id
from employees
where salary>7000 and department_id=80;

//8. 查詢80號部門工資大於8000並且佣金高於0.3的員工姓名,工資以及提成
select first_name,salary,salary * 0.3,department_id
from employees
where salary>8000 and commission_pct>0.30 and department_id=80;

//9. 查詢職位(job_id)爲’AD_PRES’的員工的工資

//模糊條件查詢

select *from employees

select first_name,job_id,salary
from employees
where job_id like ‘AD_PRES’;

//10. 查詢佣金(commission_pct)爲0或爲NULL的員工信息

//is null ,is not null,or

select *
from employees
where commission_pct is null or commission_pct=0 ;

//11. 查詢入職日期在1997-5-1到1997-12-31之間的所有員工信息

//區間比較:between

select *
from employees
where to_char(hire_date,‘yyyy-MM-dd’)
between ‘1997-05-01’ and ‘1997-12-31’ ;

//12. 顯示姓名中沒有’L’字的員工的詳細信息或含有’SM’字的員工信息

//模糊條件查詢

select *
from employees
where first_name not like ‘%l%’ or first_name like ‘%sm%’;

//13. 查詢電話號碼以5開頭的所有員工信息.

//模糊查詢

select *
from employees
where phone_number like ‘5%’;

//14. 查詢80號部門中last_name以n結尾的所有員工信息

select *
from employees
where department_id=80 and last_name like ‘%n’;

//15. 查詢所有last_name 由四個以上字母組成的員工信息

select *
from employees
where last_name like ‘%____%’;

// 單行函數練習

//1. 把hire_date列看做是員工的生日,查詢本月過生日的員工(考察知識點:單行函數)

select *
from employees
where to_char(hire_date,‘mm’) = 04;

//2. 查詢2002年下半年入職的員工(考察知識點:單行函數)
select *
from employees
where to_char(hire_date,‘yyyy-MM’) > ‘2002-06’;

//3. 打印自己出生了多少天
select sysdate-to_date(‘1996-09-30’,‘yyyy-MM-dd’) from dual;

//4. 打印入職時間超過30年的員工信息

select *
from employees
where to_char(sysdate,‘yyyy’)-to_char(hire_date,‘yyyy’)>=30;

//組函數練習

//1. 顯示各種職位的最低工資(組函數)

select job_id,min(salary)
from employees
group by job_id;

//2. 求1997年各個月入職的的員工個數(考察知識點:組函數)

select to_char(hire_date,‘MM’),count(*)
from employees
where to_char(hire_date,‘yyyy’)=‘1997’
group by to_char(hire_date,‘MM’);

//3. 查詢每個部門,每種職位的最高工資(考察知識點:分組)
select department_id,job_id,max(salary)
from employees
group by department_id,job_id;

//4. 查詢各部門的總工資
select department_id ,sum(salary)
from employees
group by department_id

//5. 查詢50號部門,60號部門,70號部門的平均工資
select department_id,avg(salary)
from employees
where department_id=50 or department_id=60 or department_id=70
group by department_id;

//6. 查詢各部門的最高工資,最低工資.
select department_id,max(salary),min(salary)
from employees
group by department_id

//7. 查詢各崗位的員工總數.

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

//8. 查詢各部門中各個崗位的平均工資.

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

發佈了38 篇原創文章 · 獲贊 6 · 訪問量 3495
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章