How do I convert this query to Eloquent syntax
SELECT x.id, x.title, points, (points - 1)/POW(((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(x.created_at))/3600)+2, 1.5) as hasil
FROM media x
JOIN (SELECT m.id,
(SUM(mp.up)-SUM(mp.down)) AS points
FROM media m
JOIN media_points mp ON mp.media_id = m.id
GROUP BY m.id) y ON y.id = x.id
ORDER BY hasil DESC
LIMIT 100
Finally i found the answer by using raw()
Media::select(DB::raw('media.*, (points - 1)/POW(((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(media.created_at))/3600)+2, 1.5) as hasil'))
->join(DB::raw('(SELECT m.id, (SUM(mp.up)-SUM(mp.down)) AS points FROM media m JOIN media_points mp ON mp.media_id = m.id GROUP BY m.id) as T'), 'T.id', '=', 'media.id')
->orderBy('hasil','desc')
->take(100)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.