I have a MySQL table called track_e_exercises
where is stored attempts in a test, every row is a new attempt. I want to know how to obtain the avg attempts in the course per person. How can I make that?
c_id
is the course id column and exe_user_id
is the user id column.
expected result for c_id=7 => (# of attempts in the course/peopple that attempted) = 1 expected result for c_id=8 => avg attempts = 3.5
Advertisement
Answer
You can use count(distinct)
:
select c_id, count(*) / count(distinct exe_user_id) as avg_attempts from t group by c_id;