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 ...
随机推荐
- bzoj 4032 [HEOI2015]最短不公共子串——后缀自动机
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4032 不是 b 的子串的话就对 b 建后缀自动机,在 a 上枚举从每个位置开始的子串或者找子 ...
- Sqlite数据库中的事务
public void testTrasaction() throws Exception{ PersonSQLiteOpenHelper helper = new PersonSQLiteOpen ...
- python开发mysql:表关系&单表简单查询
一 一对多,多对一 1.1 建立多对一 ,一对多的关系需要注意 先建立被关联的表,被关联的字段必须保证时唯一的 在创建关联的表,关联的字段一定是可以重复的 1.2 示例: 出版社 多对一,多个老师可能 ...
- 温故而知新java事务
一.什么是Java事务 通常的观念认为,事务仅与数据库相关. 事务必须服从ISO/IEC所制定的ACID原则.ACID是原子性(atomicity).一致性(consistency).隔离性 (iso ...
- 参数传递中编码问题(Get/Post 方式)(三)
自己总结的: GET方式: 1.提交方式为GET时,数据是放在请求HEADER头中的,且将数据与URL拼接后,浏览器会对拼接后的url进行编码,编码方式为浏览器默认的编码, ...
- 分布式爬虫搭建系列 之三---scrapy框架初用
第一,scrapy框架的安装 通过命令提示符进行安装(如果没有安装的话) pip install Scrapy 如果需要卸载的话使用命令为: pip uninstall Scrapy 第二,scrap ...
- Android 4 学习(12):Linkify & Broadcast event
参考<Professional Android 4 Development> Linkify Linkfy类可以在Text View中创建超链接.匹配LInkify中正则表达式的文本将被L ...
- Hibenate错误汇总:java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger
转自:https://bioubiou.iteye.com/blog/1769950 1 Hibenate异常汇总:java.lang.NoClassDefFoundError: org/jboss/ ...
- MIDL相关
根据MIDL的语义, 指针总被认为是指向单一元素而不是数组.因此以上方法中只有串中的第一个字符被封送.为此,MIDL引入了[string]特性来说明传递的是一个字符串 http://www.cnblo ...
- java基础知识(一)之数据类型和运算符
1.标识符:JAVA里面我们可以为之命名的就是标识符,如变量.方法.类等. 但是标识符只能包含字母.数字.下划线(_)和美元符号($),并且只能以字母.下划线和美元符号开头不能以数字开头.2.变量:在 ...