day34作业

六月ゝ 毕业季﹏ 提交于 2019-12-02 19:30:22
作业:
    1. 查看岗位是teacher的员工姓名、年龄
    2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
    3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
    4. 查看岗位描述不为NULL的员工信息
    5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
    6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
    7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
--创建表
create table info(
    id int unsigned primary key auto_increment,
    name char(25) not null,
    age int,
    station char(25),
    salary decimal(7,2)
)charset=utf8;


--插入数据
insert into info (name,age,station,salary) values ('engon',25,'teacher',51234.45),
('tank',35,'teacher',10000.23),('jinse',40,'teacher',23111.55),('老张',32,'清洁工',9000.00),
('neo',24,null,12000.29),('法老',23,'赛车手',40000.23),('jingou',18,'学生',1200.00);
--1. 查看岗位是teacher的员工姓名、年龄
select name,age from info where station='teacher';
+-------+------+
| name  | age  |
+-------+------+
| engon |   25 |
| tank  |   35 |
| jinse |   40 |
+-------+------+

--2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
mysql> select name,age from info where station='teacher' and age>30;
+-------+------+
| name  | age  |
+-------+------+
| tank  |   35 |
| jinse |   40 |
+-------+------+

--3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
select name,age,salary from info where station='teacher' and (salary between 9000 and 10000);

--4. 查看岗位描述不为NULL的员工信息
mysql> select * from info where station is not null;
+----+--------+------+---------+----------+
| id | name   | age  | station | salary   |
+----+--------+------+---------+----------+
|  1 | engon  |   25 | teacher | 51234.45 |
|  2 | tank   |   35 | teacher | 10000.23 |
|  3 | jinse  |   40 | teacher | 23111.55 |
|  4 | 老张   |   32 | 清洁工  |  9000.00 |
|  6 | 法老   |   23 | 赛车手  | 40000.23 |
|  7 | jingou |   18 | 学生    |  1200.00 |
+----+--------+------+---------+----------+

--5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
select name,age,salary from info where station='teacher' and salary in (10000,9000,30000);

--查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
select name,age,salary from info where station='teacher' and salary not in (10000,9000,30000);

--7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
select name,salary from info where station='teacher' and name like 'jin%';
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!