沒有人知道,如何轉換此查詢原始的QueryBuilder:轉換MySQL查詢到DB ::原始查詢
SELECT
A.ID_KANWIL,
COUNT(A.ID_CABANG) AS CABANG,
SUM(JUMLAH_KARYAWAN) AS JMLKARYAWAN,
COALESCE(B.JML_PESERTA, 0) AS JMLPESERTA
FROM ORGANISASI A
LEFT JOIN (
SELECT
ID_KANWIL,
SUM(JUMLAH_PESERTA) AS JML_PESERTA
FROM CAKUPAN
WHERE
BULAN=6
AND TAHUN=2017
AND ID_PROGRAM=1
GROUP BY
ID_KANWIL,
ID_PROGRAM
) B ON A.ID_KANWIL=B.ID_KANWIL
WHERE
A.BULAN=6
AND A.TAHUN=2017
GROUP BY
A.ID_KANWIL,
A.BULAN,
A.TAHUN
我已經試過了,
$data=colletc(DB::select(DB::raw("SELECT
A.ID_KANWIL,
COUNT(A.ID_CABANG) AS CABANG,
SUM(JUMLAH_KARYAWAN) AS JMLKARYAWAN,
COALESCE(B.JML_PESERTA, 0) AS JMLPESERTA
FROM ORGANISASI A
LEFT JOIN (
SELECT
ID_KANWIL,
SUM(JUMLAH_PESERTA) AS JML_PESERTA
FROM CAKUPAN
WHERE
BULAN=6
AND TAHUN=2017
AND ID_PROGRAM=1
GROUP BY
ID_KANWIL,
ID_PROGRAM
) B ON A.ID_KANWIL=B.ID_KANWIL
WHERE
A.BULAN=6
AND A.TAHUN=2017
GROUP BY
A.ID_KANWIL,
A.BULAN,
A.TAHUN")))->get()
,但我得到的錯誤
Call to a member function get() on array
謝謝@peter,我已經替換 - > get()與所有(),那是工作完美。 –