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. Linux下的CPU性能瓶颈分析案例

    问题描述: 在对notify执行性能测试时发现cpu负载突然飙高,cpu利用率高达95%.这时候就要排查是哪些线程消耗了cpu,并从代码层找到占用cpu的“罪魁祸首”. 步骤: 1. 先用ps+gre ...

  2. VC++ 使用MSSOAP访问WebService天气服务(客户端开发)

    绪论 本文介绍使用VC++编程实现访问天气Web服务的简单实例(例子来源于网络). Web天气服务 http://www.webxml.com.cn/WebServices/WeatherWebSer ...

  3. 在php代码中调用帝国cms头部变量temp.header的方法

    在php代码中调用帝国cms头部变量temp.header的方法 代码如下: <?php require("../e/class/connect.php"); if(!def ...

  4. WAMP设置默认访问目录

    打开httpd.conf 1.修改:DocumentRoot "F:/Project/Php" 2.修改 <Directory "F:/Project/Php&qu ...

  5. .net多线程,线程异步,线程同步,并发问题---1---ShinePans

    申请线程,输出线程状态: using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...

  6. PHP - PhpStorm 快捷键大全 PhpStorm 常用快捷键和配置(转)

    原文地址:http://www.cr173.com/html/66775_1.html PhpStorm 是 JetBrains 公司开发的一款商业的 PHP 集成开发工具,PhpStorm可随时帮助 ...

  7. Python 入门(四)List和Tuple类型

    创建list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: >>> ...

  8. 第四篇:GPU 并行编程的存储系统架构

    前言 在用 CUDA 对 GPU 进行并行编程的过程中,除了需要对线程架构要有深刻的认识外,也需要对存储系统架构有深入的了解. 这两个部分是 GPU 编程中最为基础,也是最为重要的部分,需要花时间去理 ...

  9. 将Eclipse项目导入到Android studio 中 很多点9图出现问题解决方法

    在build.gradle里添加以下两句: aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false

  10. sphinx的配置和管理.No2

    网上配置文档众多,但是对着他们的文档来做老是出问题,于是花了点时间研究了一下,写成总结,方便以后查阅.也希望学习sphinx的朋友能少走弯路.Coreseek的安装请参考:http://blog.ch ...