SELECT
    u.id AS participant_id,
    u.full_name AS participant_name,
    u.email AS participant_email,
    q.title AS quiz_name,
    m.title AS module_name,
    (SUM(CASE WHEN qo.is_correct = 1 THEN 1 ELSE 0 END) / COUNT(qres.id)) * 100 AS score_percentage
FROM
    user u
JOIN
    training_session_participant tsp ON u.id = tsp.participant_id
JOIN
    training_session ts ON tsp.training_session_id = ts.id
JOIN
    quiz_result qr ON tsp.training_session_id = qr.training_session_id AND u.id = qr.user_id
JOIN
    question_result qres ON qr.id = qres.quiz_result_id
JOIN
    question_option qo ON qres.question_option_id = qo.id
JOIN
    quiz q ON qr.quiz_id = q.id
LEFT JOIN
    module m ON q.module_id = m.id
WHERE
    ts.training_session_code = "A99T44LJW"
GROUP BY
    u.id, u.full_name, u.email, q.title, m.title;