mysql 数据操作 单表查询 where约束 between and or
WHERE约束
where字句中可以使用:
- 比较运算符:>< >= <= !=
- between 80 and 100 值在80到100之间 >=80 <=100
- in(80,90,100) 值是80或90或100 满足这个条件就可以
- like 'egon%'
pattern可以是%或_,
%表示任意多字符
_表示一个字符 - 逻辑运算符:在多个条件直接可以使用逻辑运算符 and or not
select id,name,age from employee where id >7;
执行顺序 1.from employee 2. where id >7 3. id,name,age
先找到表 再按照约束条件 从表里取要找的记录
单个条件
mysql> select id,name,age from employee where id >7;
+----+-----------+-----+
| id | name | age |
+----+-----------+-----+
| 8 | 丫丫 | 38 |
| 9 | 丁丁 | 18 |
| 10 | 星星 | 18 |
| 11 | 格格 | 28 |
| 12 | 张野 | 28 |
| 13 | 程咬金 | 18 |
| 14 | 程咬银 | 18 |
| 15 | 程咬铜 | 18 |
| 16 | 程咬铁 | 18 |
+----+-----------+-----+
9 rows in set (0.11 sec)
找出薪资大于8000的老师
多个条件
mysql> select name,post,salary from employee where post='teacher' and salary>8000;
+------------+---------+------------+
| name | post | salary |
+------------+---------+------------+
| alex | teacher | 1000000.31 |
| jingliyang | teacher | 9000.00 |
| jinxin | teacher | 30000.00 |
| 成龙 | teacher | 10000.00 |
+------------+---------+------------+
4 rows in set (0.00 sec)
薪资大于等于20000 小于等于30000
mysql> select name,salary from employee where salary >= 20000 and salary <= 30000;
+-----------+----------+
| name | salary |
+-----------+----------+
| jinxin | 30000.00 |
| 程咬金 | 20000.00 |
+-----------+----------+
2 rows in set (0.00 sec)
between 20000 and 30000
原理 >= 20000 <=30000
mysql> select name,salary from employee where salary between 20000 and 30000;
+-----------+----------+
| name | salary |
+-----------+----------+
| jinxin | 30000.00 |
| 程咬金 | 20000.00 |
+-----------+----------+
2 rows in set (0.00 sec)
小于20000 或者大于30000
mysql> select name,salary from employee where salary < 20000 or salary >30000;
+------------+------------+
| name | salary |
+------------+------------+
| alex | 1000000.31 |
| yuanhao | 3500.00 |
| liwenzhou | 2100.00 |
| jingliyang | 9000.00 |
| 成龙 | 10000.00 |
| 歪歪 | 3000.13 |
| 丫丫 | 2000.35 |
| 丁丁 | 1000.37 |
| 星星 | 3000.29 |
| 格格 | 4000.33 |
| 张野 | 10000.13 |
| 程咬银 | 19000.00 |
| 程咬铜 | 18000.00 |
| 程咬铁 | 17000.00 |
+------------+------------+
14 rows in set (0.00 sec)
between 取反
小于2000 大于30000
mysql> select name,salary from employee where salary not between 20000 and 30000;
+------------+------------+
| name | salary |
+------------+------------+
| alex | 1000000.31 |
| yuanhao | 3500.00 |
| liwenzhou | 2100.00 |
| jingliyang | 9000.00 |
| 成龙 | 10000.00 |
| 歪歪 | 3000.13 |
| 丫丫 | 2000.35 |
| 丁丁 | 1000.37 |
| 星星 | 3000.29 |
| 格格 | 4000.33 |
| 张野 | 10000.13 |
| 程咬银 | 19000.00 |
| 程咬铜 | 18000.00 |
| 程咬铁 | 17000.00 |
+------------+------------+
14 rows in set (0.00 sec)
#1:单条件查询
SELECT name FROM employee
WHERE post='sale';
#2:多条件查询
SELECT name,salary FROM employee
WHERE post='teacher' AND salary>10000;
#3:关键字BETWEEN AND
SELECT name,salary FROM employee
WHERE salary BETWEEN 10000 AND 20000;
SELECT name,salary FROM employee
WHERE salary NOT BETWEEN 10000 AND 20000;
mysql 数据操作 单表查询 where约束 between and or的更多相关文章
- mysql 数据操作 单表查询 where 约束 目录
mysql 数据操作 单表查询 where约束 between and or mysql 数据操作 单表查询 where约束 is null in mysql 数据操作 单表查询 where约束 li ...
- mysql 数据操作 单表查询 where约束 工作模式
select name,age from employee where id >7; 1.首先先找到表 from employee 2.表存在 mysql拿着约束条件 去表里 看依次匹配数 ...
- mysql 数据操作 单表查询 where约束 like 模糊匹配
mysql> select * from employee; +----+------------+--------+-----+------------+-----------+------- ...
- mysql 数据操作 单表查询 where约束 is null in
需求找出年龄是 81 或者 73 或者 28 mysql ; +----+-----------+--------+-----+------------+-----------+----------- ...
- mysql 数据操作 单表查询 where约束 练习
create table employee( id int not null unique auto_increment, name ) not null, sex enum('male','fema ...
- mysql 数据操作 单表查询 目录
mysql 数据操作 单表查询 mysql 数据操作 单表查询 简单查询 避免重复DISTINCT mysql 数据操作 单表查询 通过四则运算查询 mysql 数据操作 单表查询 concat()函 ...
- mysql 数据操作 单表查询 group by 分组 目录
mysql 数据操作 单表查询 group by 介绍 mysql 数据操作 单表查询 group by 聚合函数 mysql 数据操作 单表查询 group by 聚合函数 没有group by情况 ...
- mysql 数据操作 单表查询 group by 介绍
group by 是在where 之后运行 在写单表查询语法的时候 应该把group by 写在 where 之后 执行顺序 1.先找到表 from 库.表名 2.按照where 约束条件 过滤你想要 ...
- mysql 数据操作 单表查询
单表查询的语法 distinct 去重 SELECT 字段1,字段2... FROM 表名 库.表名 WHERE 条件 过滤 符合条件的 GROUP BY field 分组条件 HAVING 筛选 过 ...
随机推荐
- 如何用MathType编辑化学等式
MathType在数学中应用非常广泛,被大量用于编辑数学公式,MathType不仅可以用来编辑数学公式,还可以编辑化学反应式,那么MathType编辑化学等式怎么操作的呢? 具体操作如下: 1.打开M ...
- ChemDraw中如何输入化学式分隔点
ChemDraw最实用的化学结构绘图软件,在绘制化学结构时,离不开给化学结构标记原子名称,有时还需要插入分隔点,本教程以下图给出的化学结构为例,讲解ChemDraw中如何输入化学式分隔点. 化学结构 ...
- mysqldump如何针对某些数据库进行备份?针对某个数据库进行备份?
需求描述: 通过mysqldump工具对mysql服务器中的某几个数据库进行备份. 或者就对其中的一个数据库进行备份. 操作过程: 1.通过--databases参数后面加上数据库的名字进行备份 [m ...
- 火云开发课堂 - 《使用Cocos2d-x 开发3D游戏》系列 第四节:3D公告板
<使用Cocos2d-x 开发3D游戏>系列在线课程 第四节:3D公告板 视频地址:http://edu.csdn.net/course/attend/1330/20804 交流论坛:mo ...
- ssh&scp指定密钥
scp时指定密钥: scp -P22 -r -i ~/.ssh/dongjing-shanghai.pem root@kiri_pro01:/data/backup/back_from_japan ...
- docker中文、手册、教程
Docker资源 Docker官方英文资源: docker官网:http://www.docker.com Docker windows入门:https://docs.docker.com/windo ...
- 十大Material Design开源项目
介于拟物和扁平之间的Material Design自面世以来,便引起了很多人的关注与思考,就此产生的讨论也不绝于耳.本文详细介绍了在Android开发者圈子里颇受青睐的十个Material Desig ...
- json 数据分析
/* 健一健康头条 */ try { String url = "http://www.j1health.com/j1api.php/index/getJ1healthHotLists&qu ...
- 首个vue.js项目收尾中……
前言: 4.26号入手vue.js+elementUI,迄今为止我们的工作应该可以暂时告一段落了:下周开始,又是新的“征程”. 过程:站在接近完成的角度来看这个项目,似乎的确有许多事情需要自己阐述. ...
- jQuery之ajaxForm提交表单
1.jQuery的设计非常优雅,其源代码亦给人以美感,利用jQuery框架写出来的js既简练又能完美跨浏览器. 2.jquery form插件是基于jQuery开发的一套能够利用ajax技术提 ...