将查询翻译成laravel

时间:2017-08-14 12:35:14

标签: php mysql laravel

请将查询翻译成eloquent 我试了2天:

SELECT absens.kelas_id AS kelas_id
     , absens.nisn AS nisn
     , (SELECT t2.kondisi
          FROM absens t2 
         WHERE ((t2.date = '20170811') 
            AND (t2.kelas_id = 2) 
            AND (t2.nisn = absens.nisn)   
            AND (t2.jam_ke = 0))
       ) AS Jam 0
    FROM absens 
   WHERE ((absens.date = '20170811') 
      AND (absens.kelas_id = 2)) 
   GROUP 
      BY absens.nisn;

1 个答案:

答案 0 :(得分:-2)

DB::select(DB::raw("SELECT absens.kelas_id AS kelas_id
     , absens.nisn AS nisn
     , (SELECT t2.kondisi
          FROM absens t2 
         WHERE ((t2.date = '20170811') 
            AND (t2.kelas_id = 2) 
            AND (t2.nisn = absens.nisn)   
            AND (t2.jam_ke = 0))
       ) AS Jam 0
    FROM absens 
   WHERE ((absens.date = '20170811') 
      AND (absens.kelas_id = 2)) 
   GROUP 
      BY absens.nisn;
      ")
);

希望我帮助XD