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;

相关推荐
PD我是你的真爱粉21 分钟前
MySQL8新特性
数据库·mysql
shalou290141 分钟前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring
eWidget1 小时前
政务电子证照系统重构:如何解决跨模态数据的“一致性”与“安全合规”难题?
数据库·mongodb·kingbase·数据库平替用金仓·金仓数据库·文档数据库
芝士爱知识a2 小时前
【FinTech前沿】AlphaGBM:重塑期权交易的智能分析引擎——从原理到实践
数据结构·数据库·人工智能·alphagbm·期权
AC赳赳老秦2 小时前
2026主权AI趋势:DeepSeek搭建企业自有可控AI环境,保障数据安全实战
大数据·数据库·人工智能·python·科技·rabbitmq·deepseek
仍然.2 小时前
MYSQL---事务
数据库·mysql
king_harry2 小时前
openGauss 6.0 主备集群备份与恢复实战指南:基于 gs_probackup
数据库·opengauss·gs_probackup
ruxshui3 小时前
MySQL备份核心指南
数据库·mysql
霖霖总总3 小时前
[小技巧73]MySQL UUID 全面解析:UUID 的原理、结构与最佳实践
数据库·mysql
tod1133 小时前
Redis C++ 客户端开发全流程指南
数据库·c++·redis·缓存