2016-01-21 267 views
1

下面是我生MySQL查詢:需要原始查詢轉換爲laravel雄辯

SELECT T1.id, T1.department_id, COALESCE(T2.cnt, 0) AS cnt 
FROM (SELECT DISTINCT id, department_id FROM users WHERE company_id = '33') AS T1 
    LEFT JOIN ( 
      SELECT user_id, COUNT(*) AS cnt 
       FROM userlogs 
       WHERE created_at BETWEEN '2015-12-17' AND '2016-01-12' 
       GROUP BY user_id 
      ) AS T2 ON T2.user_id = t1.id 

任何一個可以幫助我將其轉換爲Eloquent?我是Laravel的新手。

+2

你真的使用'laravel-3'?你還試過了什麼? –

+0

請告訴我們你試過了什麼? –

+0

Laravel 3不再支持 –

回答

1

我解決它使用DB::query()這是非常簡單的