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

先找到表 再按照约束条件 从表里取要找的记录

单个条件

  1. mysql> select id,name,age from employee where id >7;
  2. +----+-----------+-----+
  3. | id | name | age |
  4. +----+-----------+-----+
  5. | 8 | 丫丫 | 38 |
  6. | 9 | 丁丁 | 18 |
  7. | 10 | 星星 | 18 |
  8. | 11 | 格格 | 28 |
  9. | 12 | 张野 | 28 |
  10. | 13 | 程咬金 | 18 |
  11. | 14 | 程咬银 | 18 |
  12. | 15 | 程咬铜 | 18 |
  13. | 16 | 程咬铁 | 18 |
  14. +----+-----------+-----+
  15. 9 rows in set (0.11 sec)

找出薪资大于8000的老师

多个条件

  1. mysql> select name,post,salary from employee where post='teacher' and salary>8000;
  2. +------------+---------+------------+
  3. | name | post | salary |
  4. +------------+---------+------------+
  5. | alex | teacher | 1000000.31 |
  6. | jingliyang | teacher | 9000.00 |
  7. | jinxin | teacher | 30000.00 |
  8. | 成龙 | teacher | 10000.00 |
  9. +------------+---------+------------+
  10. 4 rows in set (0.00 sec)

薪资大于等于20000 小于等于30000

  1. mysql> select name,salary from employee where salary >= 20000 and salary <= 30000;
  2. +-----------+----------+
  3. | name | salary |
  4. +-----------+----------+
  5. | jinxin | 30000.00 |
  6. | 程咬金 | 20000.00 |
  7. +-----------+----------+
  8. 2 rows in set (0.00 sec)

between 20000 and 30000

原理 >= 20000  <=30000

  1. mysql> select name,salary from employee where salary between 20000 and 30000;
  2. +-----------+----------+
  3. | name | salary |
  4. +-----------+----------+
  5. | jinxin | 30000.00 |
  6. | 程咬金 | 20000.00 |
  7. +-----------+----------+
  8. 2 rows in set (0.00 sec)

小于20000 或者大于30000

  1. mysql> select name,salary from employee where salary < 20000 or salary >30000;
  2. +------------+------------+
  3. | name | salary |
  4. +------------+------------+
  5. | alex | 1000000.31 |
  6. | yuanhao | 3500.00 |
  7. | liwenzhou | 2100.00 |
  8. | jingliyang | 9000.00 |
  9. | 成龙 | 10000.00 |
  10. | 歪歪 | 3000.13 |
  11. | 丫丫 | 2000.35 |
  12. | 丁丁 | 1000.37 |
  13. | 星星 | 3000.29 |
  14. | 格格 | 4000.33 |
  15. | 张野 | 10000.13 |
  16. | 程咬银 | 19000.00 |
  17. | 程咬铜 | 18000.00 |
  18. | 程咬铁 | 17000.00 |
  19. +------------+------------+
  20. 14 rows in set (0.00 sec)

between 取反

小于2000   大于30000

  1. mysql> select name,salary from employee where salary not between 20000 and 30000;
  2. +------------+------------+
  3. | name | salary |
  4. +------------+------------+
  5. | alex | 1000000.31 |
  6. | yuanhao | 3500.00 |
  7. | liwenzhou | 2100.00 |
  8. | jingliyang | 9000.00 |
  9. | 成龙 | 10000.00 |
  10. | 歪歪 | 3000.13 |
  11. | 丫丫 | 2000.35 |
  12. | 丁丁 | 1000.37 |
  13. | 星星 | 3000.29 |
  14. | 格格 | 4000.33 |
  15. | 张野 | 10000.13 |
  16. | 程咬银 | 19000.00 |
  17. | 程咬铜 | 18000.00 |
  18. | 程咬铁 | 17000.00 |
  19. +------------+------------+
  20. 14 rows in set (0.00 sec)
  1. #1:单条件查询
  2. SELECT name FROM employee
  3. WHERE post='sale';
  4. #2:多条件查询
  5. SELECT name,salary FROM employee
  6. WHERE post='teacher' AND salary>10000;
  7. #3:关键字BETWEEN AND
  8. SELECT name,salary FROM employee
  9. WHERE salary BETWEEN 10000 AND 20000;
  10. SELECT name,salary FROM employee
  11. 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. 最全Java学习路线图——Java学习指南

    准备篇 适用/适合人群:适合基础小白 目标:掌握JavaSE. ●技术点小节: 1.开发工具的安装配置的介绍 2.JDK安装 3.DOS环境编程 4.Eclipse的安装使用 ●JAVA基础 1.基本 ...

  2. 使用Visual Studio将C#生成DLL文件的方法

    1.命令方式 打开Visual Studio安装目录下的开发人员命令提示 译 File.cs 以产生 File.exe csc File.cs 编译 File.cs 以产生 File.dll csc ...

  3. oracle 日期函数 求年的最后一天、第一天,月的最后一天

    add_months(trunc(to_date('2013','yyyy') ,'yyyy'),12)-1  2013年最后一天 trunc(to_date('2013','yyyy') ,'yyy ...

  4. UIGestureRecognizer学习笔记2

    The concrete subclasses of UIGestureRecognizer are the following: UITapGestureRecognizer UIPinchGest ...

  5. RegisterHotKey注册快捷键

    RegisterHotKey的具体使用方使用方法如下: BOOL   RegisterHotKey( HWND   hWnd,         //响应该热键的窗口句柄 Int   id,       ...

  6. MongoDB复制集原理

    版权声明:本文由孔德雨原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/136 来源:腾云阁 https://www.qclo ...

  7. 数据一致性和io类型

    版权声明:本文由高剑林原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/106 来源:腾云阁 https://www.qclo ...

  8. JQuery中$.ajax()方法参数详解 转载

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...

  9. 1296: [SCOI2009]粉刷匠[多重dp]

    1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1919  Solved: 1099[Submit][Statu ...

  10. 【BZOJ3935】Rbtree 树形DP

    [BZOJ3935]Rbtree Description 给定一颗 N 个点的树,树上的每个点或者是红色,或者是黑色. 每个单位时间内,你可以任选两个点,交换它们的颜色. 出于某种恶趣味,你希望用最少 ...