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. vc 找到一个或多个多重定义的符号

    vc 找到一个或多个多重定义的符号, 这个问题还是不能很好的解决. 最根本的是: 把所有有关定义的部分都放在.cpp文件中,对应的.h文件中只放声明.这样在#include ""的 ...

  2. FairyGUI和NGUI对比

    一直在做Unity方面的游戏开发,经同事介绍了解到有这么一个GUI能提供跨平台的能力,有独立UI编辑器,而且功能强大,能够组合成复杂的UI界面,可以导出到Unity,Flash,Starling等,文 ...

  3. There are inconsistent line endings in the 'xxx' script. Some are Mac OS X (UNIX) and some are Windows.问题解决

    在Window上使用Visual Studio编辑Unity3D脚本时常会出现类似如下警告: 警告 1 There are inconsistent line endings in the 'Asse ...

  4. day02<Java语言基础+>

    Java语言基础(常量的概述和使用) Java语言基础(进制概述和二,八,十六进制图解) Java语言基础(不同进制数据的表现形式) Java语言基础(任意进制到十进制的转换图解) Java语言基础( ...

  5. 高级类特性----static关键字

    static 关键字 当我们编写一个类时,其实就是在描述其对象的属性和行为,而并没有产生实质上的对象,只有通过new关键字才会产生出对象,这时系统才会分配内存空间给对象,其方法才可以供外部调用. 我们 ...

  6. POJ 1837 Balance(01背包变形, 枚举DP)

    Q: dp 数组应该怎么设置? A: dp[i][j] 表示前 i 件物品放入天平后形成平衡度为 j 的方案数 题意: 有一个天平, 天平的两侧可以挂上重物, 给定 C 个钩子和G个秤砣. 2 4 - ...

  7. python2.0_day19_后台数据库设计思路

    from django.db import models # Create your models here. from django.contrib.auth.models import User ...

  8. python2.0 s12 day8 _ socketserver学习

    Socket 概念 一个socket就是一个点对点的链接.当今,大多数的通信都是基于Internet Protocl,因此大多数的网络Socket都是Internet Protocl(互联网)的通信( ...

  9. 【渗透测试学习平台】 web for pentester -8.XML

    example1: http://192.168.91.139/xml/example1.php?xml=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%2 ...

  10. 批处理bat文件dos命令复制文件

    ::将“C:\Users\ZZ\Desktop\快捷处理\我我我哦我”路径下的文件复制到“C:\Temp\我我我哦我”路径下::/S表示“复制目录和子目录,除了空的.”::/E表示“复制目录和子目录, ...