将sql内部连接自定义转换为雄辩的laravel

xam8gpfp  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(296)

我可以将我的自定义sql语法转换成雄辩的laravel吗,这是我的sql语法:

SELECT a.* FROM krs a INNER JOIN (
                SELECT kode_matakuliah, MAX(bobot) as bobot_max
                FROM krs
                WHERE nim = 133341043
                GROUP BY kode_matakuliah
            ) b ON a.bobot = b.bobot_max AND a.kode_matakuliah = b.kode_matakuliah 
WHERE nim = 133341043
uklbhaso

uklbhaso1#

明白了!我已经找到路了。

Krs::select(DB::raw('krs.*'))
   ->join(DB::raw('(SELECT kode_matakuliah, MAX(bobot) as bobot_max
       FROM krs
       WHERE nim = 133341043
       GROUP BY kode_matakuliah) as b'),function($join){
       $join->on('krs.kode_matakuliah', '=', 'b.kode_matakuliah')
          ->on('krs.bobot', '=', 'b.bobot_max');
       })
   ->where('krs.no_bukti',1)
   ->where('krs.nim',133341043)->get();

相关问题