1.向Student表中添加一条记录,id:13,name:孙七 生日:2004-06-01 性别:女 的记录
insert into student values(13,'孙楠楠','2001-11-16','女');
2.创建一个教师表 teacher, 字段为 tid(int) tname(varchar) cid(授课课程ID)
create table teacher (tid int(2) not null,tname varchar(40),cid int(3));
3.向teacher表中添加三条记录(张三,李四,王五) 张三带数学,李四语文,王五英语。
insert into teacher values(1,'张三','02'),(2,'李四','01'),(3,'王五','03');
4.删除学生表中名叫李四的学生
delete from student where Sname='李四';
5.查询学生表中所有女生
select * from student where Ssex='女';
6.将学生表中张三的名字修改为‘张若琳’。
update student set Sname='张若琳' where SId=09;
7.删除学生表中姓李且是男生的学生
delete from student where Ssex='男' and Sname like '%李%';
8.查询周梅的成绩信息(3表联合)
FROM student s , sc , course c where s.SId = sc.SId AND sc.CId = c.CId AND s.Sname='周梅';
9.查询成绩表中最高的分数
select max(score) from sc where SId>=01;
select min(score) from sc where SId>=01;
11.查询全班语文成绩最高的同学。
三种方法:
第一种方法(LEFT JOIN sc ON
):
SELECT student.sname FROM student LEFT JOIN sc ON student.SId=sc.SId
where sc.CId = (select CId from course where Cname='语文')
and sc.score=(select max(score) from sc where CId = (select CId from course where Cname='语文'));
第二种:
course c
WHERE
s.SId = sc.SId
AND c.CId = sc.CId
AND c.Cname = '语文'
AND sc.score = (
SELECT
max(score)
FROM
sc,
course c
WHERE
sc.CId = c.CId
AND c.Cname = '语文'
);
第三种:(来自我们班王同学)
order by score desc;
根据条件将符合的数据进行倒序,从大到小排序
补充
asc是和desc相反,是升序,从小到大排序
limit 1;
limit:选择几行
题目要求成绩最高的,也就是数据最大的,那便是一行
select sname,cname,score
from sc,student,course
where student.sid = sc.sid and sc.cid = course.cid and course.cname = '语文'
order by score desc
limit 1;