oracle 基础语法总结

常用简单查询汇总(必须掌握,记不住的收藏以备查看)

1、查询有奖金的员工: select* from emp where comm is not null;

2、查询没有奖金的员工信息: select * from emp where comm is null;

3、两个条件以上就得用and 如查询工资大于1500和有奖金的员工 select * from emp where sal>1500 and comm is not null;

4、表示两个条件有一个满足就可就用:or 如查询工资大于1500或者没有奖金的员工信息

Select * from emp where sal>1500 or comm is not null;

5、取反可以用not 如 查询员工工资不大于1500和有奖金的员工信息 如:

Select * from emp where not (sal>1500 or comm is not null);

6、在什么什么之间用between----and----如查询工资在1500和3000之间的员工信息:

Select * from emp where sal between 1500 and 3000;

7、查询员工编号是1236, 7889, 4563的员工具体信息: 如

Select * from emp where empno in(1236,7889,4563);

8、模糊查询用 like 一般结合"%"和""使用,其中%表示:可以匹配任意长度的内容,""表示匹配一个长度放入内容,如: 查询员工姓名中第二哥字母是M的员工信息:

Select * from emp where ename LIKE '_M%';

又如姓名中包含M的员工 Select * from emp where ename LIKE '%M%';

9、Oracle中不等于有两种表示方式"<>"和"!="

10、排序用order by {asc desc}其中asc 是升序排列 如果不写就默认按升序排列,desc是按降序排列;(简单记:三升四降), 排序语句放在sal语句的最后如: 按员工工资进行排序

Select * from emp order by sal asc(升序)

Selecct * from emp order by sal desc(降序)

Select * from emp where deptno='10' order by sal desc,hiredate asc;(查询部门10的员工工资的升序排列如果工资相等就按员工的入职时间排序)

11、group by 用于对查询的结果进行分组统计: 显示每个部门的平均工资和最高工资 如:

Select avg(sal),max(sal) from emp group by deptno;

Having 子句用于限制分组显示结果: 显示平均工资大于2000的的部门号和他的平均工资?

如:select avg(sal), deptno from emp group by deptno having avg(sal)>2000;

相关推荐
jaboo121 分钟前
postgresql从入门到精通
数据库·postgresql·langchain
晴天¥6 分钟前
记一次Oracle集群归档日志爆满之后如何处理(涉及ASM磁盘的增添。有坑必踩)
数据库·oracle
云边有个稻草人14 分钟前
Ubuntu部署Prometheus与Alertmanager:服务接入和远程监控
数据库·ubuntu·prometheus
Hoxy.R16 分钟前
记录一次Oracle 19c RAC iSCSI会话反复重连:comm error (1020) 原因定位与解决
数据库·oracle
神王宝宝 王者小学9 小时前
HBase: 看上去很美
大数据·数据库·hbase
io无心9 小时前
Shardingsphere5分库分表
数据库·mysql
wWYy.10 小时前
Mysql:主键索引 唯一索引 普通索引 前缀索引
数据库·mysql
宝杰X710 小时前
Android Room3 多平台数据库
android·数据库
sky_81061314 小时前
Oracle ERP 各模块业务管理功能及底层表说明
数据库·oracle
YMatrix 官方技术社区15 小时前
CittaBase vs. Neo4j :原生图性能实测与混合检索实践
数据库·功能测试·ymatrix