当前位置:网站首页>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';
边栏推荐
猜你喜欢

dotConnect for PostgreSQL数据提供程序

RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide

Matlab Doppler effect produces vibration signal and processing
![[AUTOSAR nine c/s principle Architecture]](/img/59/ce32c0ff58ef5d8385fe950136175b.png)
[AUTOSAR nine c/s principle Architecture]
![[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)](/img/ca/1d2473ae51c59b84864352eb17de94.jpg)
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)

寻找标杆战友 | 百万级实时数据平台,终身免费使用

用Go+绘制爱心给心爱的她表白
![[AUTOSAR 11 communication related mechanism]](/img/bf/834b0fad3a3e5bd9c1be04ba150f98.png)
[AUTOSAR 11 communication related mechanism]

MySQL foundation 04 MySQL architecture
![[AUTOSAR twelve mode management]](/img/42/292e3da3f5d488a1e8c10ea9bbfbab.png)
[AUTOSAR twelve mode management]
随机推荐
excel IF公式判断两列是否相同
Database SQL language 02 connection query
FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
Thank you for being together for these extraordinary two years!
(C language) data storage
Appuyez sur l'apprentissage de l'esprit de frappe - reconnaissance des coordonnées de fond multithreadées
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
Explain the basic concepts and five attributes of RDD in detail
攻克哈希的基本概念与实现
Basic concept and implementation of overcoming hash
First hand evaluation of Reza electronics rz/g2l development board
Solve the cache problem of reactnative using WebView
Daily topic: movement of haystack
Assets, vulnerabilities, threats and events of the four elements of safe operation
Cut point of undirected graph
按鍵精靈打怪學習-多線程後臺坐標識別
Infrared thermography temperature detection system based on arm rk3568
Win10 can't be installed in many ways Problems with NET3.5
按键精灵打怪学习-自动寻路回打怪点
Linear programming of mathematical modeling (including Matlab code)