sql table 的平均价值

avg value from a sql table

我有一个名为 track_e_exercises 的 MySQL table,其中存储了测试中的尝试,每一行都是一次新尝试。我想知道如何获得每个人在课程中的平均尝试次数。我该怎么做? c_id 是课程 ID 列,exe_user_id 是用户 ID 列。

c_id=7 的预期结果 =>(course/peopple 中的尝试次数)= 1 c_id=8 的预期结果 => 平均尝试次数 = 3.5

您可以使用 count(distinct):

select c_id, count(*) / count(distinct exe_user_id) as avg_attempts
from t
group by c_id;