我可以将自定义SQL语法转换为Eloquent 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
答案 0 :(得分:0)
得了!我找到了方法。
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();