我有这样的表格分数。
然后我使用查询来获得最大或最高平均值
SELECT stud_num, assess_type, MAX(average) FROM score
WHERE assess_type = "general" OR assess_type = "professional"
OR assess_type = "specialization"
GROUP BY stud_num, assess_type;
结果是,
但我想为每个ID添加每个最大值并获得平均值。 像学生#1 = 70 + 80/3,学生#2 = 62.5 + 76 + 72/3等 可以在一个查询中执行此操作吗?
欲望输出
stud_num | average
1 50 //avg of general, prof, special
2 71.5
3 72.16
答案 0 :(得分:1)
这必须解决您的问题。试一试:
SELECT stud_num
, (SUM(max_average)/3) as final_average
, access_type
FROM
( SELECT stud_num
, access_type
, MAX(average) as max_average
from score
where access_type IN ('general', 'professional', 'specialization')
GROUP
BY stud_name
, access_type
) as temp_score
GROUP
BY stud_num