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约束 练习的更多相关文章

  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约束 is null in

    需求找出年龄是 81 或者 73 或者 28 mysql ; +----+-----------+--------+-----+------------+-----------+----------- ...

  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++:Debug出错,提示错误在findfile.cpp (Line 369)

    调试程序的Debug版本,出现断言框,定位于库文件findfile.cpp 第369行: void CFileFind::AssertValid() const { // if you trip th ...

  2. linux Redhat 6环境上通过源码包安装DRBD 8

    环境描述: 操作系统版本:Red Hat Enterprise Linux Server release 6.6 (Santiago) 系统内核版本:2.6.32-504.el6.x86_64 DRB ...

  3. Bitmap之安卓手机壁纸的设置

    MainActivity: package com.hyzhou.imagedemo; import java.io.File; import android.os.Bundle; import an ...

  4. php开n次方

    php有开平方函数 sqrt,但没开n次方的函数 网上用根据什么数字原理,可用次方(pow)弄开方,格式为:pow(number, 1/ 开方数) 例如: 4的开平方,可以写成 pow(4, 1/2) ...

  5. VS添加命令行参数main(int argc, char** argv)

  6. 详解google Chrome浏览器(理论篇)

    注解:各位读者,经博客园工作人员反馈,hosts涉及违规问题,我暂时屏蔽了最新hosts,若已经获取最新hosts的朋友们,注意保密,不要外传.给大家带来麻烦,对此非常抱歉!!! 开篇概述 1.详解g ...

  7. Keil MDK从未有过的详细使用讲解(转)

    这博主关于MDK 的使用的文章,写的得TM的好  TM的实用! 真心收藏! 熟悉Keil C 51的朋友对于Keil MDK上手应该比较容易,毕竟界面是很像的.但ARM内核毕竟不同于51内核,因此无论 ...

  8. vsftpd配置教程

    原文:http://www.cnblogs.com/hhuai/archive/2011/02/12/1952647.html 可能会遇到的问题: http://www.cnblogs.com/wea ...

  9. MVC Route路由

    由于某些原因,需要默认区域,所以需要对路由进行设置 具体实现如下: using System.Web; using System.Web.Mvc; using System.Web.Routing; ...

  10. php 关于日期的知识总结

    1.UNIX时间戳   time() echo time(); 2.UNIX时间戳转换为日期用函数: date() 一般形式:date(); 即 echo date(date('Y-m-d H:i:s ...