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

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

用in

某个范围

mysql>  select * from employee where age in(81,73,28);
+----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
| id | name | sex | age | hire_date | post | post_comment | salary | office | depart_id |
+----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
| 2 | yuanhao | male | 73 | 2014-07-01 | teacher | NULL | 3500.00 | 401 | 1 |
| 3 | liwenzhou | male | 28 | 2012-11-01 | teacher | NULL | 2100.00 | 401 | 1 |
| 11 | 格格 | female | 28 | 2017-01-27 | sale | NULL | 4000.33 | 402 | 2 |
| 12 | 张野 | male | 28 | 2016-03-11 | operation | NULL | 10000.13 | 403 | 3 |
+----+-----------+--------+-----+------------+-----------+--------------+----------+--------+-----------+
4 rows in set (0.00 sec)
#5:关键字IN集合查询
SELECT name,salary FROM employee
WHERE salary=3000 OR salary=3500 OR salary=4000 OR salary=9000 ; SELECT name,salary FROM employee
WHERE salary IN (3000,3500,4000,9000) ; SELECT name,salary FROM employee
WHERE salary NOT IN (3000,3500,4000,9000) ;
#4:关键字IS NULL(判断某个字段是否为NULL不能用等号,需要用IS)

mysql> select name,age,post_comment from employee where post_comment is null;
+------------+-----+--------------+
| name | age | post_comment |
+------------+-----+--------------+
| alex | 78 | NULL |
| yuanhao | 73 | NULL |
| liwenzhou | 28 | NULL |
| jingliyang | 18 | NULL |
| jinxin | 18 | NULL |
| 成龙 | 48 | NULL |
| 歪歪 | 48 | NULL |
| 丫丫 | 38 | NULL |
| 丁丁 | 18 | NULL |
| 星星 | 18 | NULL |
| 格格 | 28 | NULL |
| 张野 | 28 | NULL |
| 程咬金 | 18 | NULL |
| 程咬银 | 18 | NULL |
| 程咬铜 | 18 | NULL |
| 程咬铁 | 18 | NULL |
+------------+-----+--------------+
16 rows in set (0.00 sec)

 
 
#4:关键字IS NULL(判断某个字段是否为NULL不能用等号,需要用IS)
SELECT name,post_comment FROM employee
WHERE post_comment IS NULL; SELECT name,post_comment FROM employee
WHERE post_comment IS NOT NULL; SELECT name,post_comment FROM employee
WHERE post_comment=''; 注意''是空字符串,不是null
ps:
执行
update employee set post_comment='' where id=2;
再用上条查看,就会有结果了
 
 

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. Oracle查询优化--排序

    --普通排序 SELECT * FROM emp ORDER BY sal DESC; --使用列序排序 DESC; --组合排序 DESC; --translate函数,参数分别用A.B.C表示 S ...

  2. SQL Server 查询数据库表的列数

    select count(*) from sysobjects a join syscolumns b on a.id=b.id where a.name='表名' go

  3. OpenCV学习:实现简单的图像叠加

    本实例使用简单的线性叠加方法来实现两幅图像的叠加,主要使用的知识如下: 1)线性融合 2)addWeighted函数 //! computes weighted sum of two arrays ( ...

  4. html5 经验记录 持续更新

    1 关于page cache 由于移动端浏览器webkit基本都实现了page cache(火狐叫做back-forwoad cache);所以回退操作基本不会触发onload操作了,不过上一页的状态 ...

  5. Java程序员职业规划

    Java 程序员职业规划 无论你是学习了 Java 即将进入企业工作,还是已经踏入了工作岗位的程序员.但是面对层出不穷的新技术,激增的就业压力,不断分化的开发角色,再加上 IT 发展的不明确,做出职业 ...

  6. POJ 3260 The Fewest Coins(多重背包问题, 找零问题, 二次DP)

    Q: 既是多重背包, 还是找零问题, 怎么处理? A: 题意理解有误, 店主支付的硬币没有限制, 不占额度, 所以此题不比 1252 难多少 Description Farmer John has g ...

  7. GIS-010-ArcGIS JS 三种查询模式(转)

    QueryTask.FindTask.IdentifyTask都是继承自ESRI.ArcGIS.Client.Tasks: 1.QueryTask:是一个进行空间和属性查询的功能类,它可以在某个地图服 ...

  8. Maven(二)-- 搭建私服,上传jar

    一.在setting中配置 私服的镜像,在mirrors标签中加上: <!--第一步 配置私服的镜像--> <mirror> <!--此处配置所有的构建均从私有仓库中下载 ...

  9. img标签-srcset属性

    今天看前辈的代码时,发现img标签有个陌生的srcset属性,如下: 1 <img class="Avatar" src="https://pic3.zhimg.c ...

  10. KVC与Runtime结合使用(案例)及其底层原理

    一.KVC 的用法和实践 用法 KVC(Key-value coding)键值编码,顾名思义.额,简单来说,是可以通过对象属性名称(Key)直接给属性值(value)编码(coding)“编码”可以理 ...