需求找出年龄是 81 或者 73 或者 28

  1. mysql> select * from employee where age=81 or age=73 or age=28;
  2. +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
  3. | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id |
  4. +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
  5. | 2 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 |
  6. | 3 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 |
  7. | 11 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 |
  8. | 12 | 张野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 |
  9. +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
  10. 4 rows in set (0.00 sec)

用in

某个范围

  1. mysql> select * from employee where age in(81,73,28);
  2. +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
  3. | id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id |
  4. +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
  5. | 2 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 |
  6. | 3 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 |
  7. | 11 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 |
  8. | 12 | 张野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 |
  9. +----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
  10. 4 rows in set (0.00 sec)
  1. #5:关键字IN集合查询
  2. SELECT name,salary FROM employee
  3. WHERE salary=3000 OR salary=3500 OR salary=4000 OR salary=9000 ;
  4. SELECT name,salary FROM employee
  5. WHERE salary IN (3000,3500,4000,9000) ;
  6. SELECT name,salary FROM employee
  7. WHERE salary NOT IN (3000,3500,4000,9000) ;
  1. #4:关键字IS NULL(判断某个字段是否为NULL不能用等号,需要用IS)
  1. mysql> select name,age,post_comment from employee where post_comment is null;
  2. +------------+-----+--------------+
  3. | name | age | post_comment |
  4. +------------+-----+--------------+
  5. | alex | 78 | NULL |
  6. | yuanhao | 73 | NULL |
  7. | liwenzhou | 28 | NULL |
  8. | jingliyang | 18 | NULL |
  9. | jinxin | 18 | NULL |
  10. | 成龙 | 48 | NULL |
  11. | 歪歪 | 48 | NULL |
  12. | 丫丫 | 38 | NULL |
  13. | 丁丁 | 18 | NULL |
  14. | 星星 | 18 | NULL |
  15. | 格格 | 28 | NULL |
  16. | 张野 | 28 | NULL |
  17. | 程咬金 | 18 | NULL |
  18. | 程咬银 | 18 | NULL |
  19. | 程咬铜 | 18 | NULL |
  20. | 程咬铁 | 18 | NULL |
  21. +------------+-----+--------------+
  22. 16 rows in set (0.00 sec)
  1.  
  1.  
  1.  
  1. #4:关键字IS NULL(判断某个字段是否为NULL不能用等号,需要用IS)
  2. SELECT name,post_comment FROM employee
  3. WHERE post_comment IS NULL;
  4. SELECT name,post_comment FROM employee
  5. WHERE post_comment IS NOT NULL;
  6. SELECT name,post_comment FROM employee
  7. WHERE post_comment=''; 注意''是空字符串,不是null
  8. ps
  9. 执行
  10. update employee set post_comment='' where id=2;
  11. 再用上条查看,就会有结果了
  1.  
  1.  

mysql 数据操作 单表查询 where约束 is null in的更多相关文章

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

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

  2. mysql 数据操作 单表查询 where约束 between and or

    WHERE约束 where字句中可以使用: 比较运算符:>< >=  <=  != between 80 and 100 值在80到100之间   >=80  <= ...

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

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

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

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

  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. jQuery-编辑选择结果(添加、筛选、过滤或检测)

    编辑选择结果 操作  实例  效果  备注 添加 添加选择器 $("p").add(".a") 添加类名为a的选择器 并不影响源结果集     $(" ...

  2. spring如何引用properties文件里的配置

      1.PropertyPlaceholderConfigurer类它是把属性中的定义的变量(var)替代,spring的配置文件中使用${var}的占位符 <beans><bean ...

  3. linux系统中,查看当前系统中,都在监听哪些端口

    需求描述: 查看当前系统中都监听着哪些的端口,用netstat命令,在此记录下 操作过程: 1.查看系统中都在监听哪些端口 [root@testvm home]# netstat -ntl Activ ...

  4. MongoDB启动报错

    启动mongodb的时候报错: [root@localhost bin]# ./mongod --dbpath /usr/java/mongoNode/data/db --logpath /usr/j ...

  5. 说说新唐ARM9(未完待续)

    针对通用32位微控制器的NUC970系列嵌入了由RISC机器有限公司设计的RISC处理器ARM926EJ-S,运行频率高达300 MHz,具有16 KB的I-cache,16 KB的D-cache和M ...

  6. cocos2d-x游戏引擎核心之十二——3.x新特性

    v3.0 亮点 使用 C++(C++11) 的特性取代了 Objective-C 的特性 优化了 Labels 优化了渲染器(比 v2.2 更快) 新的事件分发机制 物理引擎集成 新的 UI 对象 J ...

  7. Spring AOP教程及实例

    1.教程转载==>>:http://blog.csdn.net/wangpeng047/article/details/8556800 2.实例转载==>>:http://bl ...

  8. Android英文文档翻译系列(1)——AlarmManager

      原文:个人翻译,水平有限,欢迎看官指正.                                                              public class Ala ...

  9. javascript关于链接的一些用法

    (1)javascript:openURL() http://www.kpdown.com/search?name=Ben Nadel 此URL后边有一个name参数,只不过参数的值竟然带了空格,这样 ...

  10. 【BZOJ2329/2209】[HNOI2011]括号修复/[Jsoi2011]括号序列 Splay

    [BZOJ2329/2209][HNOI2011]括号修复/[Jsoi2011]括号序列 题解:我们的Splay每个节点维护如下东西:左边有多少多余的右括号,右边有多少多余的左括号,同时为了反转操作, ...