当前位置:网站首页>MySQL --- 数据库查询 - 条件查询
MySQL --- 数据库查询 - 条件查询
2022-07-03 00:55:00 【小雪菜本菜】
条件查询
我们知道从 MySQL 表中使用 SELECT 语句来查询数据,如需有条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句中。
语法
SELECT 字段名 FROM 表名 WHERE 条件;运算符表


BETWEEN 后面是最小值,AND 后面是最大值,表示的是一个区间,是包含最大值和最小值的
IN(...) 如果我们需要的值在括号里面就表示成立
LIKE 模糊匹配,需要用到通配符,一个是 _ 表示匹配单个字符,另一个是 % 表示匹配任意个字符
IS[NOT] NULL 判断某一个字段是不是空
查询需求
1.查询工资等于3000的员工
SELECT * FROM emp WHERE sal=3000;
2.查询工资小于1000的员工
SELECT * FROM emp WHERE sal<1000;
3.查询工资小于等于1000的员工
SELECT * FROM emp WHERE sal<=1000;
4.查询没有奖金的员工
SELECT * FROM emp WHERE emp.comm IS NULL;
5.查询有奖金的员工
SELECT * FROM emp WHERE emp.comm IS NOT NULL;
6.查询工资在1200到1800之间的员工(包含1200和1800)
SELECT * FROM emp WHERE sal>=1200 && sal<=1800;
SELECT * FROM emp WHERE sal>=1200 AND sal<=1800;
SELECT * FROM emp WHERE sal BETWEEN 1200 AND 1800;
7.查询职位为推销员,且工资小于1500的员工
SELECT * FROM emp WHERE job='salesman' AND sal<1500;
8.查询工资为800 或 3000 或 5000的员工
SELECT * FROM emp WHERE sal=800 OR sal=3000 OR sal=5000;
SELECT * FROM emp WHERE sal in(800,3000,5000);
9.查询姓名为四个字的员工 通配符 模糊查询
SELECT * FROM emp WHERE ename LIKE '____';
10.查询姓名最后一位是S的员工 通配符 % 匹配任意多个
SELECT * FROM emp WHERE ename LIKE '%S';
边栏推荐
- [自我管理]时间、精力与习惯管理
- 无向图的割点
- 用Go+绘制爱心给心爱的她表白
- [AUTOSAR nine c/s principle Architecture]
- (C language) data storage
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- First hand evaluation of Reza electronics rz/g2l development board
- 【FPGA教程案例5】基于vivado核的ROM设计与实现
- Several cases of recursive processing organization
- Canvas drawing -- bingdd
猜你喜欢

1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】

Rk3568 development board evaluation (II): development environment construction

(C language) data storage

【爱死机】《吉巴罗》被忽略的细节
![[C language] branch and loop statements (Part 1)](/img/47/6efcc59bd26e26f66c698635c26c8b.png)
[C language] branch and loop statements (Part 1)

Telephone network problems

ROS2之ESP32简单速度消息测试(极限频率)

Reading and writing speed of Reza rz/g2l arm development board storage and network measurement

Niu Ke swipes questions and clocks in

Esp32 simple speed message test of ros2 (limit frequency)
随机推荐
按键精灵打怪学习-自动回城路线的判断
[AUTOSAR II appl overview]
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
MySQL foundation 05 DML language
Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
拥抱平台化交付的安全理念
[AUTOSAR twelve mode management]
Specified interval inversion in the linked list
FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
Asynchronous, email and scheduled tasks
按键精灵打怪学习-自动寻路回打怪点
[自我管理]时间、精力与习惯管理
MySQL foundation 06 DDL
Key wizard play strange learning - multithreaded background coordinate recognition
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
[shutter] animation animation (shutter animation type | the core class of shutter animation)
Excel removes the data after the decimal point and rounds the number
Strongly connected components of digraph