目录
mysql> desc db; +--------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | name | varchar(255) | NO | | none | | | age | int(10) unsigned | NO | | NULL | | | salary | decimal(10,2) | NO | | NULL | | | career | varchar(255) | NO | | none | | +--------+------------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) mysql> insert into db (name,age,salary,career) values ('cxk',18,9500,'teacher'),('lxlt',58,1500,'teacher'),('xfxx',25,35000,'teacher'),('xxx',30,18000,'teacher'),('qwe',55,30050,'teacher'); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> select * from db; +----+------+-----+----------+---------+ | id | name | age | salary | career | +----+------+-----+----------+---------+ | 1 | cxk | 18 | 9500.00 | teacher | | 2 | lxlt | 58 | 1500.00 | teacher | | 3 | xfxx | 25 | 35000.00 | teacher | | 4 | xxx | 30 | 18000.00 | teacher | | 5 | qwe | 55 | 30050.00 | teacher | +----+------+-----+----------+---------+ 5 rows in set (0.00 sec)
查看岗位是teacher的员工姓名、年龄
mysql> select name,age from db where career='teacher'; +------+-----+ | name | age | +------+-----+ | cxk | 18 | | lxlt | 58 | | xfxx | 25 | | xxx | 30 | | qwe | 55 | +------+-----+ 5 rows in set (0.00 sec)
查看岗位是teacher且年龄大于30岁的员工姓名、年龄
mysql> select name,age from db where career='teacher' and age >30; +------+-----+ | name | age | +------+-----+ | lxlt | 58 | | qwe | 55 | +------+-----+ 2 rows in set (0.00 sec)
查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
mysql> select name,age,salary from db where career='teacher' and salary between -> 9000 and 10000; +------+-----+---------+ | name | age | salary | +------+-----+---------+ | cxk | 18 | 9500.00 | +------+-----+---------+ 1 row in set (0.00 sec)
查看岗位描述不为NULL的员工信息
mysql> select name,age,salary from db where career='teacher' and salary between -> 9000 and 10000; +------+-----+---------+ | name | age | salary | +------+-----+---------+ | cxk | 18 | 9500.00 | +------+-----+---------+ 1 row in set (0.00 sec)
查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from db where career='teacher' and salary in (10000,9000,30000); Empty set (0.00 sec)
查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
mysql> select name,age,salary from db where career='teacher' and salary not in -> (10000,9000,30000); +------+-----+----------+ | name | age | salary | +------+-----+----------+ | cxk | 18 | 9500.00 | | lxlt | 58 | 1500.00 | | xfxx | 25 | 35000.00 | | xxx | 30 | 18000.00 | | qwe | 55 | 30050.00 | +------+-----+----------+ 5 rows in set (0.00 sec)
查看岗位是teacher且名字是jin开头的员工姓名、年薪
mysql> select name,salary from db where career='teacher' and name like 'jin%'; Empty set (0.00 sec)