mysql 数据操作 单表查询 where约束 练习
create table employee(
id int not null unique auto_increment,
name varchar(20) not null,
sex enum('male','female') not null default 'male', #大部分是男的
age int(3) unsigned not null default 28,
hire_date date not null,
post varchar(50),
post_comment varchar(100),
salary double(15,2),
office int, #一个部门一个屋子
depart_id int
);
insert into employee(name,sex,age,hire_date,post,salary,office,depart_id) values
('alex','male',78,'','teacher',1000000.31,401,1),
('yuanhao','male',73,'','teacher',3500,401,1),
('liwenzhou','male',28,'','teacher',2100,401,1),
('jingliyang','female',18,'','teacher',9000,401,1),
('jinxin','male',18,'','teacher',30000,401,1),
('成龙','male',48,'','teacher',10000,401,1), ('歪歪','female',48,'','sale',3000.13,402,2),#以下是销售部门
('丫丫','female',38,'','sale',2000.35,402,2),
('丁丁','female',18,'','sale',1000.37,402,2),
('星星','female',18,'','sale',3000.29,402,2),
('格格','female',28,'','sale',4000.33,402,2), ('张野','male',28,'','operation',10000.13,403,3), #以下是运营部门
('程咬金','male',18,'','operation',20000,403,3),
('程咬银','female',18,'','operation',19000,403,3),
('程咬铜','male',18,'','operation',18000,403,3),
('程咬铁','female',18,'','operation',17000,403,3)
;
1. 查看岗位是teach
er的员工姓名、年龄
mysql> select name,age,post from employee where post='teacher';
+------------+-----+---------+
| name | age | post |
+------------+-----+---------+
| alex | 78 | teacher |
| yuanhao | 73 | teacher |
| liwenzhou | 28 | teacher |
| jingliyang | 18 | teacher |
| jinxin | 18 | teacher |
| 成龙 | 48 | teacher |
+------------+-----+---------+
6 rows in set (0.00 sec)
2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
mysql> select name,age,post from employee where post='teacher' and age>30;
+---------+-----+---------+
| name | age | post |
+---------+-----+---------+
| alex | 78 | teacher |
| yuanhao | 73 | teacher |
| 成龙 | 48 | teacher |
+---------+-----+---------+
3 rows in set (0.00 sec)
3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
mysql> select name,age,post,salary from employee where post='teacher' and salary between 9000 and 10000;
+------------+-----+---------+----------+
| name | age | post | salary |
+------------+-----+---------+----------+
| jingliyang | 18 | teacher | 9000.00 |
| 成龙 | 48 | teacher | 10000.00 |
+------------+-----+---------+----------+
2 rows in set (0.00 sec)
4. 查看岗位描述不为NULL的员工信息
mysql> select * from employee where post_comment is not null;
Empty set (0.00 sec)
5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from employee where post='teacher' and salary in(10000,9000,30000);
+------------+-----+----------+
| name | age | salary |
+------------+-----+----------+
| jingliyang | 18 | 9000.00 |
| jinxin | 18 | 30000.00 |
| 成龙 | 48 | 10000.00 |
+------------+-----+----------+
3 rows in set (0.00 sec)
6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from employee where post='teacher' and salary not in(10000,9000,30000);
+-----------+-----+------------+
| name | age | salary |
+-----------+-----+------------+
| alex | 78 | 1000000.31 |
| yuanhao | 73 | 3500.00 |
| liwenzhou | 28 | 2100.00 |
+-----------+-----+------------+
3 rows in set (0.00 sec)
7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
mysql> select name,salary*12 from employee where post='teacher' and name like 'jin%';
+------------+-----------+
| name | salary*12 |
+------------+-----------+
| jingliyang | 108000.00 |
| jinxin | 360000.00 |
+------------+-----------+
2 rows in set (0.00 sec)
mysql 数据操作 单表查询 where约束 练习的更多相关文章
- 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约束 is null in
需求找出年龄是 81 或者 73 或者 28 mysql ; +----+-----------+--------+-----+------------+-----------+----------- ...
- 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注册文本框获取焦点清空,失去焦点赋值的简单实例
在我们开发过程中特别是用户注册时会有一个效果,就是文本框获取焦点清空提示,如果用户没有输入信息失去焦点赋值上我们的提示语. <html> <head> <meta h ...
- Unity3D面试——真实的面试,unity3d面试
本来想写一个系列的,一半是抨击现在面试之水,要人之奸,用大哥的话说,要走新手是做螺丝钉和抹布用的.另一半是对出出学校的或者是自废武功转3d的朋友们提供一个比较有价值的参考.不过我时间实在仓促.没有保证 ...
- 服务端用例设计的思(tao)路!
服务端的测试简单来说就是除了前端以外的的测试. 总的来说可以分为以下两类: 1. WEB或者APP的提供业务逻辑的服务端接口测试 2. 数据库.缓存系统.中间件..jar包依赖.输入输 ...
- 连接oracle服务器超慢--原因分析
连接oracle服务器超慢:有如下原因可能会影响. 网络不好:oracle服务器跟本地网络不好. oracle服务器内存不足:导致反应超慢 监听日志listener.log太大:导致响应超慢. 所以对 ...
- linux中的目录和文件的统计
ls 目录 | wc -l find ./ -type d | wc -l //查找目录个数 find ./ -type f | wc -l ...
- 如何在Oculus官网下载OculusSetup.exe(当前时间20170720)
踩着免费的蓝灯FQ登录了Oculus官网,找了半天找不到哪里下载OculusSetup.exe,最后在最下面的支持中心找到了..... https://www.oculus.com/
- 新唐ARM9之NUC972学习历程之系统的搭建和BSP包的使用
说到嵌入式,我们首先想到的,就是它的复杂程度,LINUX,BSP,UBOOT,交叉编译,寄存器配置,等等一系列的问题,甚至有的时候我们对此一头雾水,很是头疼,不过我们今天要说的就是关于NUC972的一 ...
- 查询软件和硬件列表清单[将文章里代码另存为 list.vbs,双击运行就会出现一个html页面]
'==========================================================================' Name: 查询软件和硬件列表清单' 不支持W ...
- Spring学习笔记--初始化和销毁Bean
可以使用bean的init-method和destroy-method属性来初始化和销毁bean.定义一个Hero类: package com.moonlit.myspring; public cla ...
- Runtime 运行时之一:消息转发
解释一 上一篇文章咱们提到了Runtime的消息传递机制,主要围绕三个C语言API来展开进行的.这篇文章我将从另外三个方法来描述Runtime中另一个特性:消息转发机制. 一.消息转发机制 当向某个对 ...