ジョブ10.29

作业:
    ###1. 查看岗位是teacher的员工姓名、年龄
create database tt charset utf8;
mysql> use tt
Database changed
mysql> create table school(
-> id int unsigned auto_increment primary key,
-> name char(10) not null default 'lld',
-> age int not null default 0,
-> job varchar(20)
-> )charset utf8;
Query OK, 0 rows affected (0.02 sec)

mysql> insert into school(id,name,age,job) values (1,'ldd',24,'teacher');
Query OK, 1 row affected (0.01 sec)

mysql> select * from school;
+----+------+-----+---------+
| id | name | age | job     |
+----+------+-----+---------+
|  1 | ldd  |  24 | teacher |
+----+------+-----+---------+
1 row in set (0.00 sec)
    ###2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
mysql> insert into school(name,age,job) values('nnnnj',33,'teacher');
Query OK, 1 row affected (0.00 sec)

mysql> insert into school(name,age,job) values('ksjdjh',34,'teacher');
Query OK, 1 row affected (0.00 sec)

mysql> select * from school where age>30;
+----+--------+-----+---------+
| id | name   | age | job     |
+----+--------+-----+---------+
|  2 | nnnnj  |  33 | teacher |
|  3 | ksjdjh |  34 | teacher |
+----+--------+-----+---------+
2 rows in set (0.00 sec)
    ###3. 查看岗位是teacher且薪资在9000-10000范围内的员工姓名、年龄、薪资
mysql> alter table school add salary float not null default 0;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql>  update school set salary='9888' where age>30;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql> select * from school where salary between 9000 and 10000;
+----+--------+-----+---------+--------+
| id | name   | age | job     | salary |
+----+--------+-----+---------+--------+
|  2 | nnnnj  |  33 | teacher |   9888 |
|  3 | ksjdjh |  34 | teacher |   9888 |
+----+--------+-----+---------+--------+
2 rows in set (0.00 sec)
    ###4. 查看岗位描述不为NULL的员工信息
mysql> alter table school add descri char(25);
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select * from school;
+----+--------+-----+---------+--------+--------+
| id | name   | age | job     | salary | descri |
+----+--------+-----+---------+--------+--------+
|  1 | ldd    |  24 | teacher |      0 | NULL   |
|  2 | nnnnj  |  33 | teacher |   9888 | NULL   |
|  3 | ksjdjh |  34 | teacher |   9888 | NULL   |
+----+--------+-----+---------+--------+--------+
3 rows in set (0.00 sec)

mysql> update school set descri=0 where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from school where descri=0;
+----+-------+-----+---------+--------+--------+
| id | name  | age | job     | salary | descri |
+----+-------+-----+---------+--------+--------+
|  2 | nnnnj |  33 | teacher |   9888 | 0      |
+----+-------+-----+---------+--------+--------+
1 row in set (0.00 sec)
    ###5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
mysql> update school set salary=10000 where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update school set salary=9000 where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from school where salary in(9000,10000,3000);
+----+-------+-----+---------+--------+--------+
| id | name  | age | job     | salary | descri |
+----+-------+-----+---------+--------+--------+
|  1 | ldd   |  24 | teacher |  10000 | NULL   |
|  2 | nnnnj |  33 | teacher |   9000 | 0      |
+----+-------+-----+---------+--------+--------+
2 rows in set (0.00 sec)
    ###6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
mysql> select * from school where salary not in(9000,10000,30000);
+----+--------+-----+---------+--------+--------+
| id | name   | age | job     | salary | descri |
+----+--------+-----+---------+--------+--------+
|  3 | ksjdjh |  34 | teacher |   9888 | NULL   |
+----+--------+-----+---------+--------+--------+
1 row in set (0.00 sec)
    ###7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
mysql> update school set name='jin hua' where id=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from school where name like 'jin%';
+----+---------+-----+---------+--------+--------+
| id | name    | age | job     | salary | descri |
+----+---------+-----+---------+--------+--------+
|  1 | jin hua |  24 | teacher |  10000 | NULL   |
+----+---------+-----+---------+--------+--------+
1 row in set (0.00 sec)

おすすめ

転載: www.cnblogs.com/lidandanaa/p/11761768.html
おすすめ