1.自行创建表student,表结构如下所示
mysql> desc student;
±--------±------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±--------±------------±-----±----±--------±------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| birth | date | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| sex | varchar(5) | YES | | NULL | |
| address | varchar(50) | YES | | NULL | |
±--------±------------±-----±----±--------±------+
2.对应每条SQL插入满足和不满足条件的数据,要求查出满足条件的数据(以下只给出SQL语句)
1.查询住在changqing的学生姓名及编号并以学号降序排列
mysql> select name,id from student where address='changqing' order by id desc;
2.查询学生编号为666的学生的姓名及年龄
mysql> select name,age from student where id=666;
3.查询还未登记住址的学生有哪些
mysql> select name from student where address is null;
4.查询年龄为22,性别为male的学生ID及姓名
mysql> select id,name from student where age=22 and sex='male';
5.查询出生范围在1996-01-01到1997-01-01的学生信息
mysql> select * from student where birth between '1996-01-01' and '1997-01-01';
6.查询住在changqing、jinan、dezhou的学生信息
mysql> select * from student where address='changqing' or address='jinan' or address='dezhou';
7.查询名字中包含yan的学生信息
mysql> select * from student where name like '%yan%';
8.查询姓li的学生信息
mysql> select * from student where name like 'li%';
9.查询以cong结尾的学生信息
mysql> select * from student where name like '%cong';
10.查询学生编号第二个数字为8的学生信息
mysql> select * from student where id like '_8%';
11.查询名字中包含_的学生信息
mysql> select * from student where name like '%/_%' escape '/';
12.查询住在changqing或者jinan的学生信息
mysql> select * from student where address='changqing' or address='jinan';
13.查询没有住在changqing的学生信息
mysql> select * from student where address != 'changqing';
14.查询出生范围不是在1996-01-01到1997-01-01的学生信息
mysql> select * from student where birth not between '1996-01-01' and '1997-01-01';
15.查询名字中不包含yan的学生信息
mysql> select * from student where name not like '%yan%';