请大家赐教,谢谢
我在学习数据库时遇到了一个困难,请大家帮帮忙:下面创建了一个新表:
CREATE TABLE GradeTable
(
ID int IDENTITY(1,1) primary key,
StudentID VARCHAR(5) not null ,
StudentName VARCHAR(50),
CourseID VARCHAR(5) not null ,
CourseName VARCHAR(100),
Grade int,
TeacherID VARCHAR(5) not null ,
TeacherName VARCHAR(50)
)
下面向表中添加记录:
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S3','王五','K4','政治',53,'T4','赵老师')
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S1','张三','K1','数学',61,'T1','张老师')
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S2','李四','K3','英语',88,'T3','李老师')
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S1','张三','K4','政治',77,'T4','赵老师')
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S2','李四','K4','政治',67,'T4','周老师')
因为表中没有添加唯一性约束,我把上面记录中的前三行重新插入:
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S3','王五','K4','政治',53,'T4','赵老师')
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S1','张三','K1','数学',61,'T1','张老师')
insert into GradeTable(StudentID,StudentName,CourseID,CourseName,Grade,TeacherID,TeacherName)
values('S2','李四','K3','英语',88,'T3','李老师')
问题:
现在表中有了一些重复的记录,请用查询分析器实现“统计每个学生的选课数和平均分” 重复的
记录是垃圾数据,怎样才能正确的实现呢?请大家不吝赐教!谢。