MySQL 语句建表
一、数据准备:
1.student学生表数据:
2.teacher老师表数据:
3.course课程表数据:
4.score成绩表数据:
二、数据查询
1.查询平均成绩大于60分的同学的学生编号和学生姓名和平均成绩:
语句:select st.StuId,st.StuName as st_name,avg(sc.StuScore) from score as sc,student as st where st.StuId = sc.StuId group by st.StuId having avg(sc.StuScore) > 60;
结果:
2.查询所有学生的学号、姓名、选课数、总成绩
语句:select st.StuId,st.StuName,count(sc.StuId),sum(sc.Stuscore) from student as st,score as sc where st.StuId = sc.StuId group by sc.StuId;
结果