十、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';
相关推荐
努力的小T14 分钟前
使用 Docker 部署 Apache Spark 集群教程
linux·运维·服务器·docker·容器·spark·云计算
想要打 Acm 的小周同学呀21 分钟前
Redis三剑客解决方案
数据库·redis·缓存
rkmhr_sef21 分钟前
Redis 下载与安装 教程 windows版
数据库·windows·redis
枫叶落雨2222 小时前
08-Elasticsearch
运维·jenkins
库库林_沙琪马2 小时前
Redis 缓存穿透、击穿、雪崩:问题与解决方案
数据库·redis·缓存
Hanson Huang2 小时前
【存储中间件API】MySQL、Redis、MongoDB、ES常见api操作及性能比较
redis·mysql·mongodb·es
黄雪超2 小时前
大数据SQL调优专题——引擎优化
大数据·数据库·sql
爆更小小刘2 小时前
Linux下基本指令(4)
linux·运维·服务器
我码玄黄3 小时前
解决本地模拟IP的DHCP冲突问题
linux·运维
LUCIAZZZ3 小时前
EasyExcel快速入门
java·数据库·后端·mysql·spring·spring cloud·easyexcel