oracle数据库查询全系整理
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(,,,);
commit; --员工表
insert into employ(ename,employid,sex,age,stationid,deptid) values('王小明',,'男',,,);
commit; --部门表
insert into dept(deptid,deptname) values(,'测试部');
commit; --岗位表
insert into station values(,'测试工程师');
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 = ;
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 =
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 and
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 =
group by t2.deptname, t1.ename;
--11、删除王小明的所有信息
select * from salary; --薪水表
select * from employ; --员工表
select * from dept; --部门表
select * from station; --岗位表 delete from salary where salaryid=;
delete from employ where ename='王小明';
delete from dept where deptid=;
delete from station where stationid=;
oracle数据库查询全系整理的更多相关文章
- oracle数据库查询日期sql语句(范例)、向已经建好的表格中添加一列属性并向该列添加数值、删除某一列的数据(一整列)
先列上我的数据库表格: c_date(Date格式) date_type(String格式) 2011-01-01 0 2012-03-07 ...
- python操作oracle数据库-查询
python操作oracle数据库-查询 参照文档 http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python- ...
- C#连接Oracle数据库查询数据
C#连接Oracle数据库可以实现许多我们需要的功能,下面介绍的是C#连接Oracle数据库查询数据的方法,如果您对C#连接Oracle数据库方面感兴趣的话,不妨一看. using System; u ...
- 005.Oracle数据库 , 查询多字段连接合并,并添加文本内容
/*Oracle数据库查询日期在两者之间*/ SELECT PKID , OCCUR_DATE, PKID || ' 曾经沧海难为水 ' ||TO_CHAR( OCCUR_DATE, ' yyyy/m ...
- 004.Oracle数据库 , 查询多字段连接合并
/*Oracle数据库查询日期在两者之间*/ SELECT PKID , OCCUR_DATE, PKID || TO_CHAR( OCCUR_DATE, ' yyyy/mm/dd hh24:mi:s ...
- 001.Oracle数据库 , 查询日期在两者之间
/*Oracle数据库查询日期在两者之间*/ SELECT OCCUR_DATE FROM LM_FAULT WHERE ( ( OCCUR_DATE >= to_date( '2017-05- ...
- oracle数据库查询常用语句
1.查询SCOTT表中有多少表,并显示表的一些描述select * from all_tables WHERE owner='SCOTT' ; 2.查询oracle数据库版本select * from ...
- Oracle数据库的关键系统服务整理
在Windows 操作系统下安装Oracle 9i时会安装很多服务——并且其中一些配置为在Windows 启动时启动.在Oracle 运行在Windows 下时,有些服务可能我们并不总是需要但又害怕停 ...
- oracle数据库查询和更新
package sqltest; import java.sql.*; import parameter.BaseCanShu; public class PublicDbOracle { stati ...
随机推荐
- dockerfile初试之tomcat8封装
前面学习了一些docker相关资料,有看到dockerfile这个东东,一时没看得太明白,理论给合实践是最好的学习方法,自己做一下就行了嘛.主要步聚记录如下: 0)环境 10.202.105.96 ...
- js生成1~100随机数
(function (min,max){ var range = max - min; var rand = Math.random(); var num = min + Math.round(ran ...
- 三种实现Ajax的方式
本文主要是比较三种实现Ajax的方式 1. prototype.js 2. jquery1.3.2.min.js 3. json2.js Java代码 收藏代码 后台处理程序(Servlet),访问路 ...
- jquery中ajax异步调用接口
之前写过一个原始的.无封装的页面,没有引入任何外部js,直接实例化Ajax的XmlRequest对象去异步调用接口,参见Ajax异步调用http接口后刷新页面,可对比一下. 现在我们用jquery包装 ...
- xshell密码不让输入 修改
不允许点击输入密码:解决方案 https://zhidao.baidu.com/question/2266139012830466068.html
- rbenv配置
git clone https://github.com/rbenv/rbenv.git ~/.rbenv # 用来编译安装 ruby git clone git://github.com/sstep ...
- java里的switch循环--你妹考试落榜了
总结:switch循环,不用break.那么程序每一个case都会运行到,直到遇到break停止 package com.aa; //格子区域 //3行3列的格子 public class Bu { ...
- phantomjs 安装和试用
准备学习casperjs, 发现官网上说 it’s an extremely useful companion to PhantomJS, 所以决定下把它下来试试.下载安装(win7)没什么可说的, ...
- 1110 Complete Binary Tree
1110 Complete Binary Tree (25)(25 分) Given a tree, you are supposed to tell if it is a complete bina ...
- 1138 Postorder Traversal
题意:给出二叉树的前序序列后中序序列,输出其后序序列的第一个值. 思路:乍一看不就是前序+中序重建二叉树,然后后序遍历嘛!这么做当然不会有错,但是却没有真正领会本题的意图.本题并不是让我们输出后序序列 ...