作业:
'''
作业:
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)