title: Complex SQL or Eloquent query
body: <p>I have this Database schema</p>
  
  <p><a href="https://i.stack.imgur.com/uRr0l.png" rel="nofollow noreferrer">exercise_quiz table</a></p>
  
  <pre><code>CREATE TABLE `exercise_quiz` (
    `exercise_id` int(10) unsigned NOT NULL,
    `quiz_id` int(10) unsigned NOT NULL,
    `user_id` int(10) unsigned NOT NULL,
    `answer` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`exercise_id`,`quiz_id`,`user_id`),
    KEY `exercise_quiz_user_id_foreign` (`user_id`),
    KEY `exercise_quiz_quiz_id_foreign` (`quiz_id`),
    CONSTRAINT `exercise_quiz_exercise_id_foreign` FOREIGN KEY (`exercise_id`) REFERENCES `exercises` (`id`) ON DELETE CASCADE,
    CONSTRAINT `exercise_quiz_quiz_id_foreign` FOREIGN KEY (`quiz_id`) REFERENCES `quizzes` (`id`) ON DELETE CASCADE,
    CONSTRAINT `exercise_quiz_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/VfHdd.png" rel="nofollow noreferrer">exercises table</a></p>
  
  <pre><code>CREATE TABLE `exercises` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `body` text COLLATE utf8mb4_unicode_ci NOT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    `course_id` int(10) unsigned NOT NULL,
    `score` int(11) DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `exercises_course_id_foreign` (`course_id`),
    CONSTRAINT `exercises_course_id_foreign` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`) ON DELETE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=145 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/hcuPZ.png" rel="nofollow noreferrer">quizzes table</a></p>
  
  <pre><code>CREATE TABLE `quizzes` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `question` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RgQDf.png" rel="nofollow noreferrer">Example of data in exercise_quiz</a></p>
  
  <p>How can I retrieve this, either with raw SQL or with Eloquent, in such a way as I’d have one single row for each exercise_id with one column with the average answer for each quiz_id ? something like</p>
  
  <pre><code>exercise_id ---  avg_quiz_1 ---- avg_quiz_2 ---- avg_quiz_3 ...
  </code></pre>