Here my MySQL query (work in phpMyAdmin) :
SELECT waktu_kerusakan, workcenter, COUNT(workcenter) AS jumlah_repair
FROM repair WHERE year(waktu_kerusakan)='2019' GROUP BY workcenter ,
month(waktu_kerusakan) BETWEEN 1 and 6 Order By jumlah_repair Desc
then, i try in Laravel Syntax like this below (not work) :
$sql = Main::groupBy('workcenter')->select('workcenter', DB::raw('count(*) as frekuensi'))
->whereYear('waktu_kerusakan', 'like', "%".$tahun."%")
->OrderBy('frekuensi', 'Desc')
->groupBy(DB::raw("MONTH(waktu_kerusakan)"), [1, 6])
->get();
Please anyone help me to convert the MySQL query to Laravel Syntax. Thank you!
2
Answers
Try this.
Try this query :