days34

若如初见. 提交于 2019-12-02 20:40:18

作业:

'''
作业:
1. 查看岗位是teacher的员工姓名、年龄
2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
4. 查看岗位描述不为NULL的员工信息
5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
'''

# 先创建一个数据库如下:
mysql> select * from test;
+----+-------+-----+---------+------------------+
| id | name  | age | post    | salary           |
+----+-------+-----+---------+------------------+
|  1 | jane  |  26 | NULL    | 35000.0000000000 |
|  2 | nick  |  18 | teacher | 20000.0000000000 |
|  3 | tank  |  25 | teacher | 25000.0000000000 |
|  4 | jason |  23 | teacher | 23000.0000000000 |
|  5 | engo  |  25 | manager | 30000.0000000000 |
+----+-------+-----+---------+------------------+
5 rows in set (0.04 sec)

# 1. 查看岗位是teacher的员工姓名、年龄
mysql>  select name,age from test where post="teacher";
+-------+-----+
| name  | age |
+-------+-----+
| nick  |  18 |
| tank  |  25 |
| jason |  23 |
+-------+-----+
3 rows in set (0.10 sec)

# 2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
mysql> select name,age from test where post="teacher" and age>30;
Empty set (0.00 sec)

# 3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
mysql> select name,age,salary from test where post="teacher" and salary between 1000 and 9000;
Empty set (0.03 sec)

# 4. 查看岗位描述不为NULL的员工信息
mysql> select * from  where post != "NULL";
+----+-------+-----+---------+------------------+
| id | name  | age | post    | salary           |
+----+-------+-----+---------+------------------+
|  2 | nick  |  18 | teacher | 20000.0000000000 |
|  3 | tank  |  25 | teacher | 25000.0000000000 |
|  4 | jason |  23 | teacher | 23000.0000000000 |
|  5 | engo  |  25 | manager | 30000.0000000000 |
+----+-------+-----+---------+------------------+
4 rows in set (0.00 sec)

# 5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from test where post="teacher" and salary in (9000,10000,30000);
Empty set (0.04 sec)

# 6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from test where post="teacher" and salary not in (9000,10000,30000);
+-------+-----+------------------+
| name  | age | salary           |
+-------+-----+------------------+
| nick  |  18 | 20000.0000000000 |
| tank  |  25 | 25000.0000000000 |
| jason |  23 | 23000.0000000000 |
+-------+-----+------------------+
3 rows in set (0.00 sec)

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