十、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';
相关推荐
江团1io08 分钟前
深入解析MVCC:多版本并发控制的原理与实现
java·经验分享·mysql
island131410 分钟前
【Redis#9】其他数据结构
数据结构·数据库·redis
言之。22 分钟前
Django REST框架:ModelViewSet全面解析
数据库·python·django
-Xie-25 分钟前
Mysql杂志(十四)——Mysql逻辑架构
数据库·mysql·架构
葵花日记31 分钟前
LINUX--编译器gcc/g++
linux·运维·服务器
西贝爱学习35 分钟前
数据库系统概论的第六版与第五版的区别
数据库·oracle
光路科技1 小时前
光路科技将携工控四大产品亮相工博会,展示工业自动化新成果
运维·科技·自动化
PAQQ2 小时前
解决 ubuntu 重启串口号变化
linux·运维·ubuntu
emma羊羊2 小时前
【SQL注入】延时盲注
数据库·sql·网络安全
dyxal3 小时前
linux系统安装wps
linux·运维·wps