dimanche 22 juillet 2018

How to write RIGHT JOIN with union query in laravel query builder

I am new in laravel, and i have query like below that want to be queried using laravel builder, but unfortunately i am quite confused how to write it using laravel builder query or eloquent.

SELECT
  idMonth,
  MONTHNAME(STR_TO_DATE(idMonth, '%m')) as m,
  IFNULL(count(id), 0) as total
FROM kontrak_penjualans
RIGHT JOIN (
  SELECT 1 as idMonth
  UNION SELECT 2 as idMonth
  UNION SELECT 3 as idMonth
  UNION SELECT 4 as idMonth
  UNION SELECT 5 as idMonth
  UNION SELECT 6 as idMonth
  UNION SELECT 7 as idMonth
  UNION SELECT 8 as idMonth
  UNION SELECT 9 as idMonth
  UNION SELECT 10 as idMonth
  UNION SELECT 11 as idMonth
  UNION SELECT 12 as idMonth
) as Month
ON Month.idMonth = month(`tgl_kontrak`)
GROUP BY Month.idMonth

how to write it in eloquent or queries in laravel? especially for the RIGHT JOIN. :(



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire