gpt4 book ai didi

MYSQL:根据平均值对结果进行排序

转载 作者:行者123 更新时间:2023-11-29 22:08:23 24 4
gpt4 key购买 nike

我有一张这样的 table

------------------------------------------------------------
| 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 |
------------------------------------------------------------

我想根据每门类(class)计算的平均值对结果 (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

因此我们必须像这样计算每门类(class)的平均值,并根据我们得到的平均值显示coursecodeids

并且成绩应根据特定类(class)的最大出现次数来显示。

我正在运行此查询,但它没有按预期工作

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

最佳答案

试试这个

SELECT 
(AVG(workload) + AVG(easiness)) / 2 AS result
FROM
metagen.new_table
GROUP BY coursecodeid;

关于MYSQL:根据平均值对结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31935883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com