十、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';
相关推荐
速捷工控 PLC触摸屏还原程序1 小时前
欧姆龙NB上传密码忘了,换屏前怎么保留原程序?
运维·服务器·欧姆龙
方便面不加香菜2 小时前
Docker Volume -- 对照总结及综合实战案例操作演示
运维·docker·容器
爱勇宝2 小时前
SSL 证书别再手动续了:acme.sh + Let's Encrypt + 云厂商 DNS 全自动实战
运维·服务器
城北徐宫2 小时前
MySQL数据类型整理
数据库·mysql
数据库小学妹3 小时前
数据库容量规划:四个数与扩容触发线
运维·数据库·后端
时间的拾荒人3 小时前
Redis Cluster 集群详解:分片算法、搭建、故障处理与扩容实战
数据库·redis·算法·集群
去码头整点薯条985 小时前
NFS服务器
linux·运维·服务器
蜗牛一步步往上爬6 小时前
第一章 初识Linux shell
linux·运维·服务器
纆兰6 小时前
MySQL的多表查询
数据库·mysql
七夜zippoe6 小时前
Nexent 模型配置:4 字段与 9 个槽位
数据库·人工智能·模型·nexent