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'\';
相关推荐
loopfde成序2 小时前
Playwright 与 CDP 多账号并发采集架构:标签页生命周期治理与联网问答证据链留存实践
数据库·架构
毅炼3 小时前
多 Agent 不会自动提速:先看任务图和改动怎么合
数据库·软件工程
GeW3 小时前
入行 Linux 与数据库运维:一条路径、三项习惯、一个考证观
linux·数据库
拖延症晚期的Liu5 小时前
数据表的操作
大数据·数据库·sql
月夏8 小时前
10 万行全表扫描抓个正着:第一次给 MySQL 加索引
mysql·性能优化
FungLeo9 小时前
FengCMS · PHP+MySQL 升级实录 · 数据库驱动封装:mysqli 预处理与 affected_rows 关闭后变 -1 的坑
数据库·mysql·php·工程实践·fengcms
YYYing.9 小时前
【Redis剑指offer系列 (二) 】Redis线程模型
数据库·redis·缓存·八股
维爱智VR认知学能10 小时前
Python SQLite本地训练记录表迁移失败回滚与事务验证
数据库·python·单元测试·sqlite·软件工程
OpenCSG10 小时前
客户案例|Dell携手OpenCSG打造AI原生超节点
数据库·人工智能·ai-native
TDengine (老段)10 小时前
TDengine IDMP ---- Excel 插件
大数据·数据库·excel·时序数据库·tdengine·涛思数据