我不知道的內部SQL中time_diff
方法:如何將此查詢轉換爲Laravel Query Builder?
SELECT t1.started_at as chain_break,
time_to_sec(timediff(t1.started_at,IFNULL(
(SELECT MAX(t2.ended_at)
FROM status_records t2
WHERE t2.user_id=189
AND t2.started_at< t1.started_at
), t1.started_at
)
)
)/3600 AS time_off
FROM status_records t1
WHERE t1.user_id=189
ORDER BY t1.ended_at DESC
LIMIT 6
有沒有一個很好的辦法做到這一點,除了把這個查詢在DB::query
爲原料SQL?
你會如何使用'selectRaw'達到相同的結果,我的查詢? – mvpasarel