我有一张这样的表
------------------------------------------------------------
| id | coursecodeid | grade | workload | easiness |
------------------------------------------------------------
| 1 | 10 | A+ | 5 | 4 |
| 2 | 10 | A+ | 2 | 4 |
| 3 | 10 | B | 3 | 3 |
| 4 | 11 | B+ | 2 | 3 |
| 5 | 11 | A+ | 5 | 4 |
| 6 | 12 | B | 3 | 3 |
| 7 | 11 | B+ | 7 | 8 |
| 8 | 11 | A+ | 1 | 2 |
------------------------------------------------------------
我想根据每门课程的平均值计算结果(coursecodeid
)。
平均值会是这样的
all workload values of the grade against courseid
+ all easiness values of the grade against courseid
/ 2
从这个例子中coursecodeid = '10'
有三个条目
avgworkload(5+ 2 + 3)/3=x
avgeasiness(4 + 4 + 3)/3 = y
answer x+y/2 = z
所以我们必须像这样计算每门课程的平均值,并根据我们获得的平均值显示coursecodeids
和等级应根据特定课程的最大出现次数显示。
我正在运行此查询,但它没有按预期工作
SELECT
coursecode.id,
feedback.grade CourseGrade,
(( AVG( workload ) + AVG( easiness )) /2 ) as Avg
FROM coursecode
LEFT JOIN feedback ON feedback.coursecodeID = coursecode.id
GROUP BY coursecode.id
ORDER BY Avg DESC
LIMIT 11
答案 0 :(得分:0)
试试这个
SELECT
(AVG(workload) + AVG(easiness)) / 2 AS result
FROM
metagen.new_table
GROUP BY coursecodeid;