十、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';
相关推荐
爱敲代码的小鱼4 小时前
事务核心概念与隔离级别解析
java·开发语言·数据库
Mr.徐大人ゞ4 小时前
6.用户及权限管理
数据库·postgresql
赵渝强老师4 小时前
【赵渝强老师】Oracle多租户容器数据库
数据库·oracle
IT技术分享社区4 小时前
GTID 结构升级 + JSON 视图强化,MySQL 9.6 创新版带来哪些性能提升?
数据库·程序员
阿杰 AJie4 小时前
MySQL 聚合函数
android·数据库·mysql
菜鸟小九4 小时前
redis高级(存储能力问题)
数据库·redis·缓存
三不原则4 小时前
实战:混沌工程入门,模拟服务器宕机的故障演练
运维·kubernetes·chaos mesh
+VX:Fegn08954 小时前
计算机毕业设计|基于springboot + vue酒店预订系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
cws2004015 小时前
MFA双因素用户使用手册
运维·windows·网络安全·github·邮件·邮箱
JavaGuide5 小时前
IntelliJ IDEA 2026.1 EAP 发布!拥抱 Java 26,Spring Boot 4 深度支持!
java·后端·mysql·springboot·idea·大厂面试·javaguide