oracle數據庫方面的知識到今天已經整理了12篇。當然,這不是終點,這只是一個開始,希望我寫的文章可以幫助更多初學數據庫的童鞋快速上手,如果你覺得文章對你有幫助,那么恭喜你已經入門了,數據庫里面的知識有很多,多到讓你可以從入門到放棄。那么你可以通過該篇文章快速入門oracle中關於查詢的各種姿勢:
oracle課程大綱:
如果你想拿一些數據庫的習題練習,下面的例子或許是一個不錯的選擇!
--題目
--1、新員工王小明,員工編號是11,性別是男,年齡30,崗位編號是5,崗位是測試工程師,部門編號是3,
--部門名稱是測試部,薪水6000(基本工資2800,獎金3200);
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表
1題答案
--薪水表 insert into salary(salaryid,employid,basesalary,bonussalary) values(11,11,2800,3200); commit; --員工表 insert into employ(ename,employid,sex,age,stationid,deptid) values('王小明',11,'男',30,5,3); commit; --部門表 insert into dept(deptid,deptname) values(3,'測試部'); commit; --崗位表 insert into station values(5,'測試工程師'); commit;
--2、王小明試用期過了,表現非常好,公司決定給他基本工資調薪10%,獎金調15%;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表 update salary set basesalary = basesalary + basesalary * 0.1, bonussalary = bonussalary + bonussalary * 0.15
where salaryid = 11; commit;
--3、查詢測試部門最高薪水,最低薪水,平均薪水,顯示最高薪水,最低薪水,平均薪水;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表 select t2.deptname 部門, max(t3.basesalary + t3.bonussalary) 最高薪, min(t3.basesalary + t3.bonussalary) 最低薪, avg(t3.basesalary + t3.bonussalary) 平均薪資 from employ t1, dept t2, salary t3 where t1.employid = t3.employid and t2.deptid = t1.deptid and t2.deptid = 3 group by t2.deptname;
--4、查詢所有部門的最高薪水,最低水,平均薪水,顯示部門,最高薪水,最低薪水,平均薪水,並按部門名升序排序;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表
select t3.deptid 部門名稱,t3.deptname 部門名字, max(t2.basesalary+t2.bonussalary) 最高薪, min(t2.basesalary+t2.bonussalary) 最低薪, avg(t2.basesalary+t2.bonussalary) 平均薪資 from employ t1, salary t2, dept t3 where t1.employid=t2.employid and t1.deptid=t3.deptid group by t3.deptid,t3.deptname order by t3.deptname asc;
--5、統計測試部門有多少員工,顯示員工數;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表 select t2.deptname 部門名字, count(t1.employid) 人數 from employ t1, dept t2 where t1.deptid = t2.deptid and t2.deptid = group by t2.deptname;
--6、統計所有部門員工數,並按部門進行升序排序,顯示部門,員工數;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表
select t2.deptname 部門名字, count(t1.employid) 員工總數 from employ t1, dept t2 where t1.deptid = t2.deptid group by t2.deptname order by t2.deptname asc;
--7、查詢所有姓王的所有員工信息;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表 select *
from employ t1, salary t2, dept t3, station t4 where t1.employid = t2.employid and t1.deptid = t3.deptid and t1.stationid = t4.stationid and t1.ename like '王%' order by t1.employid;
--8、按部門,性別統計平均薪水;
select t2.deptname 部門名字, t1.sex 性別, round(avg(t3.basesalary + t3.bonussalary)) 平均薪水 from employ t1, dept t2, salary t3 where t1.deptid = t2.deptid and t1.employid = t3.employid group by t2.deptname, t1.sex;
--9、查詢30到40歲的平均薪水;
select t1.ename 姓名, avg(t2.basesalary + t2.bonussalary) 平均薪資 from employ t1, salary t2 where t1.employid = t2.employid and t1.age between 30 and 40 group by t1.ename;
--10、查詢測試部薪水最高的員工,顯示員工姓名;
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表 select t1.ename 員工姓名, t2.deptname 部門名字, max(t3.basesalary + t3.bonussalary) 薪水 from employ t1, dept t2, salary t3 where t1.deptid = t2.deptid and t1.employid = t3.employid and t2.deptid = 3 group by t2.deptname, t1.ename;
--11、刪除王小明的所有信息
select * from salary; --薪水表 select * from employ; --員工表 select * from dept; --部門表 select * from station; --崗位表 delete from salary where salaryid=11; delete from employ where ename='王小明'; delete from dept where deptid=3; delete from station where stationid=5;