在test数据库中创建teacher表,表结构如下图所示(id设置为主键自增长)
向表中添加记录,字段对应值分别为(209,毛不易,男,604,4000,黑龙江齐齐哈尔)
删除表中Number是201并且sex是女的教师信息
DELETE from teacher where Number=201 and Sex="女";
查询表中Number字段的值是202,205或207教师的所有记录
SELECT * from teacher WHERE Number in(202,205,207);
5.修改表中Number值是202教师的姓名为“马云”
UPDATE teacher SET Name="马云" where Number=202;
6.查询成绩最高的前三条信息
SELECT * from teacher ORDER BY Salary desc LIMIT 1,3;
7.查询姓名中包含张的信息
SELECT * from teacher Where Name like "%张%";
8.查询男女生的个数信息
SELECT count(*) ,Sex from teacher GROUP BY Sex ;
9.查询薪资在1800到3600之间的信息(使用多种方式实现)
SELECT * from teacher where Salary>1800 and Salary<3600;
SELECT * from teacher WHERE Salary BETWEEN 1800 AND 3600;
向student表中添加记录如下图所示(10分)
INSERT into student VALUES(1,'张三',98,'北京','11111111@qq.com'),(2,'李四',88,'上海','11111112@qq.com'),(3,'王五',78,'广州','11111113@qq.com'),(4,'赵六',68,'深圳','11111114@qq.com'),(5,'孙七',58,'杭州','11111115@qq.com'),(6,'小红',48,'北京','11111116@qq.com'),(7,'小黑',99,'上海','11111117@qq.com'),(8,'小绿',100,'杭州','11111118@qq.com'),(9,'小粉',60,'杭州','1111119@qq.com'),(10,'小紫',70,'黑龙江','11111110@qq.com');
使用sql语句查询出表中所有score>70的同学的id,name,score
SELECT id,name,score from student where score>70 ;
.更改name字段的数据类型为varchar(50)
ALTER TABLE student MODIFY name varchar(50);
7.向表中添加一个字段,字段名称为“pingjia”,字段类型为varchar(20)
ALTER TABLE student add pingjia varchar(20);
更改姓名是张三的同学的分数为88
update student set score=88 where name="张三";
如果80分为及格线,查询出所有及格的同学的详细信息
SELECT * from student where score>80;
使用关键字in,查询id值是1或5或7的同学的基本信息
SELECT * from student where id in(1,5,7);
查询id值在5至8的所有同学的基本信息
SELECT * FROM student where id BETWEEN 5 and 7;
11.查询id值在5至8的所有同学的基本信息
SELECT * FROM student where id BETWEEN 5 and 7;
查询姓名是小红并且分数大于60的同学的基本信息
SELECT * FROM student where name ="小红" and score>60;
13.查询姓名是小红或者分数大于90的同学的基本信息
SELECT * FROM student where name ="小红" or score>90;