当前位置:网站首页>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';
边栏推荐
- Database SQL language 02 connection query
- MongoDB系列之MongoDB常用命令
- kivy教程之在 Kivy App 中使用 matplotlib 的示例
- 每日一题之干草堆的移动
- [shutter] image component (cached_network_image network image caching plug-in)
- [case sharing] let the development of education in the new era advance with "number"
- leetcode:871. 最低加油次数【以前pat做过 + 最大堆 +贪心】
- MySQL foundation 06 DDL
- Kivy教程大全之 创建您的第一个kivy程序 hello word(教程含源码)
- Usage of using clause in kingbases alter table
猜你喜欢
Basic concept and implementation of overcoming hash
MySQL basics 03 introduction to MySQL types
[AUTOSAR II appl overview]
Excel calculates the difference between time and date and converts it into minutes
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
dotConnect for PostgreSQL数据提供程序
leetcode 2097 — 合法重新排列数对
[AUTOSAR five methodology]
用Go+绘制爱心给心爱的她表白
Find a benchmark comrade in arms | a million level real-time data platform, which can be used for free for life
随机推荐
How wide does the dual inline for bread board need?
excel表格计算时间日期的差值,并转化为分钟数
Meibeer company is called "Manhattan Project", and its product name is related to the atomic bomb, which has caused dissatisfaction among Japanese netizens
Key wizard hit strange learning - automatic path finding back to hit strange points
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
Specified interval inversion in the linked list
拥抱平台化交付的安全理念
MySQL
[AUTOSAR five methodology]
12_微信小程序之微信视频号滚动自动播放视频效果实现
Correctly distinguish the similarities and differences among API, rest API, restful API and web service
这不平凡的两年,感谢我们一直在一起!
合并K个已排序的链表
无向图的割点
Embrace the safety concept of platform delivery
Machine learning terminology
MongoDB系列之MongoDB常用命令
Infrared thermography temperature detection system based on arm rk3568
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
[AUTOSAR eight OS]