mysql 数据操作 单表查询 where约束 is null in
需求找出年龄是 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的更多相关文章
- mysql 数据操作 单表查询 where 约束 目录
mysql 数据操作 单表查询 where约束 between and or mysql 数据操作 单表查询 where约束 is null in mysql 数据操作 单表查询 where约束 li ...
- mysql 数据操作 单表查询 where约束 between and or
WHERE约束 where字句中可以使用: 比较运算符:>< >= <= != between 80 and 100 值在80到100之间 >=80 <= ...
- mysql 数据操作 单表查询 where约束 工作模式
select name,age from employee where id >7; 1.首先先找到表 from employee 2.表存在 mysql拿着约束条件 去表里 看依次匹配数 ...
- mysql 数据操作 单表查询 where约束 like 模糊匹配
mysql> select * from employee; +----+------------+--------+-----+------------+-----------+------- ...
- mysql 数据操作 单表查询 where约束 练习
create table employee( id int not null unique auto_increment, name ) not null, sex enum('male','fema ...
- mysql 数据操作 单表查询 目录
mysql 数据操作 单表查询 mysql 数据操作 单表查询 简单查询 避免重复DISTINCT mysql 数据操作 单表查询 通过四则运算查询 mysql 数据操作 单表查询 concat()函 ...
- mysql 数据操作 单表查询 group by 分组 目录
mysql 数据操作 单表查询 group by 介绍 mysql 数据操作 单表查询 group by 聚合函数 mysql 数据操作 单表查询 group by 聚合函数 没有group by情况 ...
- mysql 数据操作 单表查询 group by 介绍
group by 是在where 之后运行 在写单表查询语法的时候 应该把group by 写在 where 之后 执行顺序 1.先找到表 from 库.表名 2.按照where 约束条件 过滤你想要 ...
- mysql 数据操作 单表查询
单表查询的语法 distinct 去重 SELECT 字段1,字段2... FROM 表名 库.表名 WHERE 条件 过滤 符合条件的 GROUP BY field 分组条件 HAVING 筛选 过 ...
随机推荐
- jQuery-编辑选择结果(添加、筛选、过滤或检测)
编辑选择结果 操作 实例 效果 备注 添加 添加选择器 $("p").add(".a") 添加类名为a的选择器 并不影响源结果集 $(" ...
- spring如何引用properties文件里的配置
1.PropertyPlaceholderConfigurer类它是把属性中的定义的变量(var)替代,spring的配置文件中使用${var}的占位符 <beans><bean ...
- linux系统中,查看当前系统中,都在监听哪些端口
需求描述: 查看当前系统中都监听着哪些的端口,用netstat命令,在此记录下 操作过程: 1.查看系统中都在监听哪些端口 [root@testvm home]# netstat -ntl Activ ...
- MongoDB启动报错
启动mongodb的时候报错: [root@localhost bin]# ./mongod --dbpath /usr/java/mongoNode/data/db --logpath /usr/j ...
- 说说新唐ARM9(未完待续)
针对通用32位微控制器的NUC970系列嵌入了由RISC机器有限公司设计的RISC处理器ARM926EJ-S,运行频率高达300 MHz,具有16 KB的I-cache,16 KB的D-cache和M ...
- cocos2d-x游戏引擎核心之十二——3.x新特性
v3.0 亮点 使用 C++(C++11) 的特性取代了 Objective-C 的特性 优化了 Labels 优化了渲染器(比 v2.2 更快) 新的事件分发机制 物理引擎集成 新的 UI 对象 J ...
- Spring AOP教程及实例
1.教程转载==>>:http://blog.csdn.net/wangpeng047/article/details/8556800 2.实例转载==>>:http://bl ...
- Android英文文档翻译系列(1)——AlarmManager
原文:个人翻译,水平有限,欢迎看官指正. public class Ala ...
- javascript关于链接的一些用法
(1)javascript:openURL() http://www.kpdown.com/search?name=Ben Nadel 此URL后边有一个name参数,只不过参数的值竟然带了空格,这样 ...
- 【BZOJ2329/2209】[HNOI2011]括号修复/[Jsoi2011]括号序列 Splay
[BZOJ2329/2209][HNOI2011]括号修复/[Jsoi2011]括号序列 题解:我们的Splay每个节点维护如下东西:左边有多少多余的右括号,右边有多少多余的左括号,同时为了反转操作, ...