MYSQL SUM GROUP BY [英] MYSQL SUM GROUP BY
问题描述
我正在一所高中的分级制度。
I'm working on a high school grading system.
在我的学校,成绩可以通过再加工的问题而改变,我保存这些变化的日期。
At my school, grades can be changed by reworking problems and I store these changes with dates.
我有一个正确返回平均值的函数,因为最近的等级被标记为值为'1'的当前字段。我希望使函数能够返回过去某个日期的最新成绩。我正在绘制他们的平均值如何随时间变化的图表。
I have a function that properly returns averages because the most recent grade is flagged with a "current" field with a value of '1'. I'd like to make the function capable of returning the most recent grade with respect to a date in the past. I'm making a graph of how their average has changed over time.
我想要做的是这样的:
select sum(grades.points)
from grades
where date < 'thedate'
order by date DESC
group by assignmentID
我不能t用和和分组。它错误...
I can't use sum and group by. It errors...
我能想到的最好的做法是做一个子选择。 ?任何其他的想法。
The best I can think of is to do a sub-select. Any other thoughts?
推荐答案
GROUP BY有来ORDER BY之前:
GROUP BY has to come before ORDER BY:
SELECT SUM(g.points)
FROM GRADES g
WHERE g.date < 'thedate'
GROUP BY g.assignmentid
ORDER BY g.date DESC
这篇关于MYSQL SUM GROUP BY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!