0

课程表:courseId,courseName,tutor
学生表:studentId,studentName
Marks 表:marksId,studentId,courseId,marks
如果需要更多信息请评论

在此处输入图像描述


<\br>

CREATE VIEW maxmarks 
AS
SELECT b.studentName,courseId from [dbo].[zz_16_Marks_tbl] a,[dbo].[zz_16_Student_tbl] b
WHERE a.studentId=b.studentId AND marks in(
SELECT MAX(marks),courseId FROM [dbo].[zz_16_Marks_tbl] GROUP BY courseId)
4

1 回答 1

0
CREATE VIEW maxmarks 
AS
WITH CTE AS (SELECT MAX(marks),courseId FROM [dbo].[zz_16_Marks_tbl] GROUP BY courseId )
SELECT b.studentName,a.courseId 
from [dbo].[zz_16_Marks_tbl] a
INNER JOIN [dbo].[zz_16_Student_tbl] b ON a.studentId=b.studentId 
INNER JOIN CTE c ON a.courseId =c.courseId and a.marks=b.marks
于 2012-06-10T18:49:50.157 回答