首页 > 解决方案 > 使用 sql 中的请求不起作用并识别

问题描述

我的请求有问题,请求无法识别 WITH()。我在 Ubuntu 和 MySQL 上工作,我能得到帮助吗?

DB::select(DB::raw("WITH liststudentsoff as (
        SELECT tbl_etudiants.*, tbl_cours.idCours FROM dependance_groupes
        inner join tbl_etudiants on tbl_etudiants.idStudent = dependance_groupes.studentID
        inner join tbl_cours on tbl_cours.groupID = dependance_groupes.groupID
        inner join tbl_formations on tbl_formations.idFormation = tbl_cours.formationID
        )
        SELECT * FROM liststudentsoff
        LEFT JOIN tbl_absences ON liststudentsoff.idStudent = tbl_absences.studentID AND liststudentsoff.idCours = tbl_absences.coursID
        WHERE liststudentsoff.idCours = ".$request->idCours." and liststudentsoff.formationID = ".$cours->formationID.""));

错误显示:

    [previous exception] [object] (PDOException(code: 42000): 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 'liststudentsoff as (
        SELECT tbl_etudiants.*, tbl_cours.idCours FROM ' at line 1 at /var/www/html/emarge-backoffice/vendor/laravel/framework/src/Illuminate/Database/Connection.php:338)

标签: mysqlsqllaraveleloquentlaravel-8

解决方案


推荐阅读