に私は、クエリを実行しているが、私はそれを実行すると、それはPHP SQLSTATE [42000]構文エラーまたはアクセス違反:1064クエリ
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' count(distinct exams.user_id) as count_user_mhs from `users` where `users.type`' at line 1 (SQL: select `universities`.`name`, count(distinct exams.user_id) as count_user_dsn from `users` where `users.type` = 0, count(distinct exams.user_id) as count_user_mhs from `users` where `users.type` = 1, count(exams.subject_id) as count_subject, sum(exams.score) as count_score, TIME_FORMAT(SUM(TIMEDIFF(exams.exam_end_date, exams.exam_start_date)), "%H:%i:%s") as count_time from `exams` inner join `universities` on `universities`.`id` = `exams`.`university_id` inner join `users` on `users`.`id` = `exams`.`user_id` where exists (select * from `universities` where `exams`.`university_id` = `universities`.`id`) group by `user_id` order by `count_score` desc, `count_time` asc)
$exams = Exam::join('universities', 'universities.id', '=', 'exams.university_id')
->join('users', 'users.id', '=', 'exams.user_id')
->select('universities.name',DB::raw('count(distinct exams.user_id) as count_user_dsn from `users` where `users.type` = 0'),DB::raw('count(distinct exams.user_id) as count_user_mhs from `users` where `users.type` = 1'),DB::raw('count(exams.subject_id) as count_subject'),DB::raw('sum(exams.score) as count_score'),DB::raw('TIME_FORMAT(SUM(TIMEDIFF(exams.exam_end_date, exams.exam_start_date)), "%H:%i:%s") as count_time'));
を返し誰が助けることはできますか?私は推測している、それはDB::raw
式と関係がある。しかし、私は何が間違っているのか正確には分かりません。
1)これは警告ではありません。これはエラーです。 2)エラーメッセージ全体をコピーしていないので、何が間違っているのか分からない。 3)コードから作成したSQLクエリlaravelを共有していないため、エラーの特定に役立ちます。しかし、生のSQL部分のカウントを持つサブクエリは間違って見えます。 4)あなたがここで達成しようとしているものを正確に記述したなら、それはまた助けになるでしょう。どこでミスをしたのかがわかることが1つあるので、実際のソリューションを作成するのに役立つと思います。 – Shadow
[詳細を読む](https://stackoverflow.com/questions/23515347/how-can-i-fix-mysql-error-1064)。 – tadman
プレーンエラーメッセージを貼り付けると、デバッグに役立ちます。 – BDS