我在mysql中创建了这个函数,但该函数无效。动机是从包含每个科目,课堂,学期和学校课程中的学生分数的视图中获得最高分。 subjectid
,termid
,sessionid
和class
将从php传递给该函数。我的目标是获得最高分。
CREATE FUNCTION highestscore (class CHAR(20),subjectid INT, termid AS INT,sessionid INT)
RETURNS INT
BEGIN
SELECT Max(total) AS hscore
FROM reportsheetsubjectsview
WHERE class=class AND subjectid=subjectid
AND termid=termid AND sessionid=sessionid
RETURN hscore;
END
已编辑的存储过程版本
CREATE DEFINER = root @ localhost PROCEDURE highestscore(IN subjectid INT,IN class VARCHAR(10),IN termid INT,IN sessionid INT,OUT highesttotalscore INT)
确定性
开始SELECT Max(总计)INTO highesttotalscore FROM scoreview WHERE class = class
AND subjectid = subjectid AND termid = termid AND sessionid = sessionid;
结束
答案 0 :(得分:0)
在您的选择中添加GROUP BY
子句。
SELECT Max(total) AS hscore
FROM reportsheetsubjectsview
WHERE class=class AND subjectid=subjectid
AND termid=termid AND sessionid=sessionid GROUP BY class, subjectid, termid, sessionid