我不知道如何在此处收到此错误消息:
以下是查询:
SELECT t1.*,t2.totalAvg, ABS(`average for this subject`-totalAvg) AS Difference, 100*MIN(`average for this subject`,totalAvg)/MAX(`average for this subject`,totalAvg) AS precent
FROM (SELECT StudentFirstName,StudentLastName,ClassName,AVG(Grade) AS `average for this subject`
FROM tests
INNER JOIN students ON tests.StudentID=students.StudentID
GROUP BY StudentFirstName,StudentLastName,ClassName
) t1
JOIN (SELECT StudentFirstName,StudentLastName,AVG(`average for this subject`) as totalAvg
FROM (SELECT StudentFirstName,StudentLastName,ClassName,AVG(Grade) AS `average for this subject`
FROM tests
INNER JOIN students ON tests.StudentID=students.StudentID
GROUP BY StudentFirstName,StudentLastName,ClassName
) t
GROUP BY StudentFirstName,StudentLastName
) t2
ON t1.StudentFirstName=t2.StudentFirstName and t1.StudentLastName=t2.StudentLastName
答案 0 :(得分:2)
您的代码可能有其他错误,但这在MySQL中肯定是错误的:
MIN(`average for this subject`, totalAvg)
MIN()
只接受一个参数。据推测,您需要LEAST()
:
LEAST(`average for this subject`, totalAvg)