AND SC.SCORE=(SELECT MAX(SCORE) FROM T_SCORE WHERE SC.COURSENO=CO..COURSENO)
select top 1 sc.Score,stu.StudentName,co.CourseName from T_Score sc inner join T_Student stu on sc.StudentNo=stu.StudentNo inner join T_Course co on sc.CourseNo=co.CourseNo where co.CourseName=@Course order by sc.Score desc
CREATE PROCEDURE [dbo].[GetMaxScore] @Course nvarchar(100) as begin select sc.Score,stu.StudentName,co.CourseName from T_Score as sc join T_Student as stu on sc.StudentNo = stu.StudentNo left join T_Course as co on sc.CourseNo = co.CourseNo where co.CourseName=@Course and sc.Score=(select max(Score) from T_SCORE where sc.CourseNo=co.CourseNo) end GOexec GetMaxScore'语文'这样吗
SELECT sc.Score , stu.StudentName , co.CourseName FROM T_Score sc INNER JOIN T_Student stu ON sc.StudentNo = stu.StudentNo INNER JOIN T_Course co ON sc.CourseNo = co.CourseNo WHERE co.CourseName = @Course AND sc.Score = ( SELECT MAX(Score) FROM T_Score WHERE CourseNo = sc.CourseNo );--加上CourseNo按课程取最高分
CREATE PROCEDURE [dbo].[GetMaxScore] @Course nvarchar(100) as begin select sc.Score,stu.StudentName,co.CourseName from T_Score as sc join T_Student as stu on sc.StudentNo = stu.StudentNo left join T_Course as co on sc.CourseNo = co.CourseNo where co.CourseName=@Course and sc.Score=(select max(Score) from T_SCORE where CourseNo=sc.CourseNo) end GOexec GetMaxScore'语文' 好像就是多了一个CO
select top 1 sc.Score,stu.StudentName,co.CourseName
from T_Score sc
inner join T_Student stu on sc.StudentNo=stu.StudentNo
inner join T_Course co on sc.CourseNo=co.CourseNo
where co.CourseName=@Course
order by sc.Score desc
【SQL Server版块】提问的智慧
http://bbs.csdn.net/topics/391996442
代码贴图的同时把语句贴出来,这样方便大家直接COPY来更改你的BUG
@Course nvarchar(100)
as
begin
select sc.Score,stu.StudentName,co.CourseName
from T_Score as sc
join T_Student as stu on sc.StudentNo = stu.StudentNo
left join T_Course as co on sc.CourseNo = co.CourseNo
where co.CourseName=@Course and sc.Score=(select max(Score) from T_SCORE where sc.CourseNo=co.CourseNo)
end
GOexec GetMaxScore'语文'这样吗
SELECT sc.Score ,
stu.StudentName ,
co.CourseName
FROM T_Score sc
INNER JOIN T_Student stu ON sc.StudentNo = stu.StudentNo
INNER JOIN T_Course co ON sc.CourseNo = co.CourseNo
WHERE co.CourseName = @Course
AND sc.Score = ( SELECT MAX(Score)
FROM T_Score
WHERE CourseNo = sc.CourseNo
);--加上CourseNo按课程取最高分
@Course nvarchar(100)
as
begin
select sc.Score,stu.StudentName,co.CourseName
from T_Score as sc
join T_Student as stu on sc.StudentNo = stu.StudentNo
left join T_Course as co on sc.CourseNo = co.CourseNo
where co.CourseName=@Course and sc.Score=(select max(Score) from T_SCORE where CourseNo=sc.CourseNo)
end
GOexec GetMaxScore'语文'
好像就是多了一个CO