DQL( 数据查询语言)

1. 基本查询

select * from 表名;

select 字段,字段2,... from 表名;

select * from 表名 where 筛选条件;

select 字段,字段2,... from 表名 where 筛选条件;

2. 范围查询

复制代码
select * from emp where sal = 3000; 
select * from emp where sal != 3000;
select * from emp where sal >= 3000;
select * from emp where sal <= 3000;
select * from emp where sal > 3000;
select * from emp where sal < 3000;
select * from emp where sal <> 3000;   -- 不等于

3. 包含查询

复制代码
select * from emp where deptno in(10,20);

4. 闭区间查询

复制代码
select * from emp where sal between 950 and 2450;

5. 逻辑查询

逻辑查询 not>and>or and:遇假则假 or:遇真则真 not:取反

复制代码
and:遇假则假  or:遇真则真  not:取反
--查询emp表中20号部门,薪资大于2000的员工的信息
select * from emp where deptno=20 and sal>2000;
--查询emp表中,岗位是SALESMAN或者ANALYST的员工信息
select * from emp where job='SALESMAN' or job='ANALYST';
--查询不是老板的员工信息
select * from emp where not job='PRESIDENT';

6. 空值查询

is null 为空 is not null 不为空

复制代码
select * from emp where comm is null;
select * from emp where comm is not null;

7. 模糊查询

通配符:

_:代表这个位置只有1个字符;

%:代表这个位置有0个或者无数个字符;

复制代码
--查询emp表格员工的工种是以M开头的员工信息
select * from emp where job like'M%';
--查询员工姓名倒数第2个字母是E的员工信息
select * from emp where ename like'%E_';
  • 查询表格中带有%的数据 -- escape

需要把%或者_这个通配符转义称为普通的字符串

复制代码
--查询表格中带有%的数据
select * from op9 where n like'%\%%' escape'\';
--查询表格中带有_的数据
select * from op9 where n like'%\_%' escape'\';
相关推荐
WeiQ_8 分钟前
解决phpstudy 8.x软件中php8.2.9没有redis扩展的问题
数据库·redis·缓存
DashVector5 小时前
向量检索服务 DashVector产品计费
数据库·数据仓库·人工智能·算法·向量检索
KYGALYX5 小时前
在Linux中备份msyql数据库和表的详细操作
linux·运维·数据库
檀越剑指大厂6 小时前
金仓KReplay:定义数据库平滑迁移新标准
数据库
努力成为一个程序猿.6 小时前
【Flink】FlinkSQL-动态表和持续查询概念
大数据·数据库·flink
kali-Myon6 小时前
NewStarCTF2025-Week4-Web
sql·安全·web安全·php·ctf·ssti·ssrf
毕设十刻7 小时前
基于Vue的学分预警系统98k51(程序 + 源码 + 数据库 + 调试部署 + 开发环境配置),配套论文文档字数达万字以上,文末可获取,系统界面展示置于文末
前端·数据库·vue.js
liliangcsdn7 小时前
如何利用约束提示优化LLM在问题转sql的一致性
数据库·sql
熙客8 小时前
Kubernetes是如何保证有状态应用数据安全和快速恢复的
mysql·云原生·容器·kubernetes
Java爱好狂.8 小时前
分布式ID|从源码角度深度解析美团Leaf双Buffer优化方案
java·数据库·分布式·分布式id·es·java面试·java程序员