以下是我的原始MySQL
查询:
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
的新手。
答案 0 :(得分:1)
我使用DB::query()
解决了这个问题非常简单