laravel中两列的总和

时间:2017-12-10 16:11:14

标签: arrays laravel filter group-by sum

请帮我解决Laravel中两列的总和,比如 screenshot of a table

我的控制器看起来像这样:

  $rekap= DB::table('skpds')
                  ->join('usulans','skpds.idSkpd','=','usulans.idSkpd')
                  ->join('usulanhonors','skpds.idSkpd','=', 'usulanhonors.idSkpd')

                  ->groupBy('nama_skpd')

                  ->get( array(
                    DB::raw( 'SUM(usulans.apbd) AS apbd' ),
                    DB::raw( 'min(usulanhonors.jumlah_usulan_gaji) AS jumlah_usulan_gaji' ),
                     DB::raw( 'sum(apbd + jumlah_usulan_gaji) AS semua' ),
                    'nama_skpd'
                    ));

1 个答案:

答案 0 :(得分:0)

你必须在两列之间传递乘号,如

DB::raw('sum(quantity*per_qty) AS total')