数据表操作练习

通过mysql新建teacher表如下:

mysql> create table teacher(name char(10)not null default 'xxx',age int not null
 default 0,salary decimal(6,1))charset=utf8;
mysql> insert into teacher(name,age,salary)values('tank',18,32001.5);
mysql> insert into teacher(name,age,salary)values('json',18,32001.5);
mysql> insert into teacher(name,age,salary)values('nick',25,35000.7);
mysql> insert into teacher(name,age,salary)values('echo',26,38000.7);
mysql> select*from teacher;
+------+-----+---------+
| name | age | salary  |
+------+-----+---------+
| tank |  18 | 32001.5 |
| json |  18 | 32001.5 |
| nick |  25 | 35000.7 |
| echo |  26 | 38000.7 |
+------+-----+---------+
4 rows in set (0.00 sec)
1. 查看岗位是teacher的员工姓名、年龄
2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
4. 查看岗位描述不为NULL的员工信息
5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪

?

  1. 查看岗位是teacher的员工姓名、年龄
mysql> select name,age from teacher;
+------+-----+
| name | age |
+------+-----+
| tank |  18 |
| json |  18 |
| nick |  25 |
| echo |  26 |
+------+-----+
4 rows in set (0.00 sec)
  1. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
mysql> select name,age from teacher where age>30;
Empty set (0.00 sec)
  1. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
mysql> select*from teacher where salary>1000 and salary<9000;
Empty set (0.00 sec)
  1. 查看岗位描述不为NULL的员工信息
mysql> select*from teacher where name!=null;
Empty set (0.00 sec)
  1. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name ,age,salary from teacher where salary in(10000,9000,30000);
Empty set (0.00 sec)
  1. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from teacher where salary not in(10000,9000,30000);
+------+-----+---------+
| name | age | salary  |
+------+-----+---------+
| tank |  18 | 32001.5 |
| json |  18 | 32001.5 |
| nick |  25 | 35000.7 |
| echo |  26 | 38000.7 |
+------+-----+---------+
4 rows in set (0.00 sec)
  1. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
mysql> select name,salary from teacher where name like 'jin%';
Empty set (0.00 sec)

相关推荐