十、MySQL(DQL)条件查询

1、基础语法:

sql 复制代码
select 字段列表 from 表名 where 条件列表;

2、实际操作:

(1)初始化表格

(2)查询number大于444的员工

sql 复制代码
-- 查询number大于444的员工
select * from things where number>444;

(3)查询ID=6的员工

sql 复制代码
-- 查询ID=6的员工
select * from things where ID=6;

(4)查询address为空的员工

sql 复制代码
-- 查询address为空的员工
select * from things where address is null;

(5)查询address不为空的员工

sql 复制代码
-- 查询address不为空的员工
select * from things where address is not null;

(6)查询number不等于333的员工

sql 复制代码
-- 查询number不等于333的员工
select * from things where number!=333;

(7)查询number在222到555之间的员工

&&:表示且

and:表示且

between......and......:between之后为最小值,and之后为最大值

sql 复制代码
-- 查询number在222到555之间的员工
select * from things where number>=222 && number<=555;
select * from things where number>=222 and number<=555;
select * from things where number between 222 and 555;
/*注意,between之后为最小值,and之后为最大值*/

(8)查询data等于2005或2009的员工

or:表示或

in(参数1,参数2,参数3......):符合参数即可输出

sql 复制代码
-- 查询data等于2005或2009的员工
select * from things where date=2005 or date=2009;
select * from things where date in(2005,2009);
/*in后数值能满足其一,即可*/

(9)模糊匹配:查询地址最后一位为1的员工信息

_下划线:每一个下划线,代表一个占位

%数字:表示从末尾开始匹配,符合即可输出

sql 复制代码
-- 模糊匹配:查询地址最后一位为1的员工信息
select * from things where address like '_____1';
select * from things where address like '%1';
相关推荐
泡海椒几秒前
深度解析JQuick-SQL SQL解析与AST生成机制|分布式SQL原理
数据库·分布式·sql
天远数科2 分钟前
零信任架构实战:基于天远企业年报信息核验构建自动化供应商准入资质合规审查网关
运维·人工智能·架构·自动化
SelectDB10 分钟前
订单表改成实时更新后,我把主键模型的坑踩了一遍
大数据·数据库·数据分析
TangGeeA11 分钟前
Control CLI Tutorial:用 aio 从终端控制 aiopsterm
运维·人工智能
devilnumber14 分钟前
Redis 数据类型 + 项目落地场景(面试版,全面、实用,后端常用)
数据库·redis·面试
惠惠软件14 分钟前
PDF加盖骑缝章标注工具,PDF 文档上批量添加骑缝章或盖章的小工具
数据库·pdf·办公文件
SelectDB15 分钟前
压完一轮 TPC-H SF100,我才学会怎么读基准数字
大数据·数据库
lhdz_bj17 分钟前
Mysql Server配置详解
mysql·配置·file·config·1024程序员节·option·选项
VIP_CQCRE21 分钟前
上线 AI 分站别一次改完:一套可回滚的配置与验收流程
运维·产品设计·ai工具·技术教程·acedatacloud
Shell运维手记30 分钟前
Shell 结构化命令知识点总结(case、for、while)
运维·microsoft·shell·脚本