WHERE约束

where字句中可以使用:

    1. 比较运算符:>< >=  <=  !=
    2. between 80 and 100 值在80到100之间   >=80  <=100
    3. in(80,90,100) 值是80或90或100    满足这个条件就可以
    4. like 'egon%'
      pattern可以是%或_,
      %表示任意多字符
      _表示一个字符
    5. 逻辑运算符:在多个条件直接可以使用逻辑运算符 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的更多相关文章

  1. mysql 数据操作 单表查询 where 约束 目录

    mysql 数据操作 单表查询 where约束 between and or mysql 数据操作 单表查询 where约束 is null in mysql 数据操作 单表查询 where约束 li ...

  2. mysql 数据操作 单表查询 where约束 工作模式

    select name,age from employee where id >7; 1.首先先找到表   from employee 2.表存在 mysql拿着约束条件  去表里 看依次匹配数 ...

  3. mysql 数据操作 单表查询 where约束 like 模糊匹配

    mysql> select * from employee; +----+------------+--------+-----+------------+-----------+------- ...

  4. mysql 数据操作 单表查询 where约束 is null in

    需求找出年龄是 81 或者 73 或者 28 mysql ; +----+-----------+--------+-----+------------+-----------+----------- ...

  5. mysql 数据操作 单表查询 where约束 练习

    create table employee( id int not null unique auto_increment, name ) not null, sex enum('male','fema ...

  6. mysql 数据操作 单表查询 目录

    mysql 数据操作 单表查询 mysql 数据操作 单表查询 简单查询 避免重复DISTINCT mysql 数据操作 单表查询 通过四则运算查询 mysql 数据操作 单表查询 concat()函 ...

  7. mysql 数据操作 单表查询 group by 分组 目录

    mysql 数据操作 单表查询 group by 介绍 mysql 数据操作 单表查询 group by 聚合函数 mysql 数据操作 单表查询 group by 聚合函数 没有group by情况 ...

  8. mysql 数据操作 单表查询 group by 介绍

    group by 是在where 之后运行 在写单表查询语法的时候 应该把group by 写在 where 之后 执行顺序 1.先找到表 from 库.表名 2.按照where 约束条件 过滤你想要 ...

  9. mysql 数据操作 单表查询

    单表查询的语法 distinct 去重 SELECT 字段1,字段2... FROM 表名 库.表名 WHERE 条件 过滤 符合条件的 GROUP BY field 分组条件 HAVING 筛选 过 ...

随机推荐

  1. 总结ASP.NET C#中经常用到的13个JS脚本代码

    1.按钮前后台事件 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click ...

  2. error C2065: “m_Pic”: 未声明的标识符

    public: CPicture m_Pic; 要写在头文件里! 而不能是cpp文件的public里!

  3. 第四章 Spring.Net 如何管理您的类___对象的自动装配

    由于这几天都比较忙,所以对笔记暂时没有更新. Spring.NET具有自动装配的能力,也就是说,Spring.NET可以通过对象的定义自动分辨某个对象的协作对象.自动装配是针对单个对象(按:针对每个协 ...

  4. ios iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)

    iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) 转自容芳志大神的博客:http://www.cnblogs.com/stoic/archive/2013/02/27/2940 ...

  5. Linux中下载、解压、安装文件(转)

    原文地址:http://www.cnblogs.com/red-code/p/5539399.html 一.将解压包发送到linux服务器上: 1.在windos上下载好压缩包文件后,通过winscp ...

  6. PHP-001

    ThinkPHP单字母函数(快捷方法)使用总结 http://www.cnblogs.com/caicaizi/p/5173093.html

  7. 关于直播学习笔记-002-Red5 & Sewise Player & Wirecast

    一.工具软件 [1]. 视频采集端 Red5 Demo:http://192.168.31.107:5080/demos/simpleBroadcaster.html Telestream:Wirec ...

  8. 【渗透测试学习平台】 web for pentester -5.代码执行

    Example 1 http://192.168.106.154/codeexec/example1.php?name=".system('uname -a');// Example 2 h ...

  9. Unity官网针对IOS开发有比较好的建议

    Unity官网针对IOS开发有比较好的建议,我总结了翻译如下,后面附上原文. 尽量控制定点数量(注意所谓顶点不是建模时的顶点,而是引擎渲染时的顶点.例如,模型一个顶点如果设置了2个法向,那么对引擎来说 ...

  10. coreseek/sphinx CentOS6.4下安装

    一.在CentOS6.4下安装coreseek之前需要预先安装以下软件 1.打开终端 输入 su 获取管理员权限 2.输入命令 yum install make gcc g++ gcc-c++ lib ...