oracle数据库查询全系整理


    oracle数据库方面的知识到今天已经整理了12篇。当然,这不是终点,这只是一个开始,希望我写的文章可以帮助更多初学数据库的童鞋快速上手,如果你觉得文章对你有帮助,那么恭喜你已经入门了,数据库里面的知识有很多,多到让你可以从入门到放弃。那么你可以通过该篇文章快速入门oracle中关于查询的各种姿势:

oracle课程大纲:

    第一章:oracle数据库登录

  第二章:oracle数据库基本操作

  第三章:oracle数据库数据类型和约束

  第四章:oracle数据库创建表

  第五章:oracle数据库数据插入、修改、删除

  第六章:oracle数据库单表查询

  第七章:oracle数据库日期函数处理

  第八章:oracle数据库列的操作

  第九章:oracle数据库多表查询一部

  第十章:oracle数据库多表查询二部

  第十一章: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;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM