十、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';
相关推荐
z123456789863 分钟前
2026最新两款AI编程工具深度对比实测
java·数据库·ai编程
程序猿DD5 分钟前
一个 API Key,统一调用大模型、生图和联网搜索
数据库·网关
用户713335851562437 分钟前
MySQL - InnoDB 的 Buffer Pool
mysql
尽兴-1 小时前
企业业务系统架构选型与渐进式演进
运维·系统架构·devops
TlSfoward1 小时前
抓包代理链路下的 TLS 指纹变化分析 TLSFOWARD抓包工具
数据库·爬虫·网络协议·搜索引擎·php
数智化管理手记1 小时前
账龄分析手工统计易遗漏?自动账龄分析工具怎么搭建
大数据·网络·数据库·人工智能·数据挖掘
通信小小昕1 小时前
Ubuntu 26.04 中文输入法安装
linux·运维·ubuntu
LabVIEW开发2 小时前
NI Package Manager安装LabVIEW时InternalServerError错误
网络·数据库·labview·labview知识·labview功能·labview程序
SelectDB2 小时前
PostgreSQL 实时同步到 Apache Doris:一站式 CDC 解决方案
数据库
壮哥_icon2 小时前
【Android 系统开发】使用 BAT 脚本高效自动化管理 /system/priv-app/ 系统应用(安装与卸载)
android·运维·自动化