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 筛选 过 ...
随机推荐
- 最全Java学习路线图——Java学习指南
准备篇 适用/适合人群:适合基础小白 目标:掌握JavaSE. ●技术点小节: 1.开发工具的安装配置的介绍 2.JDK安装 3.DOS环境编程 4.Eclipse的安装使用 ●JAVA基础 1.基本 ...
- 使用Visual Studio将C#生成DLL文件的方法
1.命令方式 打开Visual Studio安装目录下的开发人员命令提示 译 File.cs 以产生 File.exe csc File.cs 编译 File.cs 以产生 File.dll csc ...
- oracle 日期函数 求年的最后一天、第一天,月的最后一天
add_months(trunc(to_date('2013','yyyy') ,'yyyy'),12)-1 2013年最后一天 trunc(to_date('2013','yyyy') ,'yyy ...
- UIGestureRecognizer学习笔记2
The concrete subclasses of UIGestureRecognizer are the following: UITapGestureRecognizer UIPinchGest ...
- RegisterHotKey注册快捷键
RegisterHotKey的具体使用方使用方法如下: BOOL RegisterHotKey( HWND hWnd, //响应该热键的窗口句柄 Int id, ...
- MongoDB复制集原理
版权声明:本文由孔德雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/136 来源:腾云阁 https://www.qclo ...
- 数据一致性和io类型
版权声明:本文由高剑林原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/106 来源:腾云阁 https://www.qclo ...
- JQuery中$.ajax()方法参数详解 转载
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- 1296: [SCOI2009]粉刷匠[多重dp]
1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1919 Solved: 1099[Submit][Statu ...
- 【BZOJ3935】Rbtree 树形DP
[BZOJ3935]Rbtree Description 给定一颗 N 个点的树,树上的每个点或者是红色,或者是黑色. 每个单位时间内,你可以任选两个点,交换它们的颜色. 出于某种恶趣味,你希望用最少 ...