0
我在SQL這樣複雜查詢:如何通過Laravel Eloquent執行這個複雜的查詢?
Logs::select(DB::raw(
'COUNT(*) as numberOfPlays'
), 'track_id')
->where('time', '>', $days)
->orderBy('numberOfPlays', 'DESC')->take(100)
->with('track', 'track.album')
->groupBy(\DB::raw("track_id"))->orderBy('numberOfPlays', 'DESC');
我如何可以運行上述查詢返回的數據進一步查詢:
SELECT distinct(albumId) as id,
band,albumName as name,
SUM(numberOfPlays) as numberOfPlays
FROM (
SELECT COUNT(*) as numberOfPlays,
tracks.album_id as albumId,
a.name as albumName,b.name as band
FROM logs l
LEFT JOIN tracks ON tracks.id=l.track_id
LEFT JOIN albums a ON tracks.album_id = a.id
LEFT JOIN bands b ON b.id = tracks.band_id
WHERE l.time>$days
GROUP by trackid
ORDER BY numberOfPlays DESC LIMIT 0,100) t
GROUP BY albumId ORDER BY numberOfPlays DESC");
到目前爲止,我已經使用這個成功retreived內查詢?
如果不使用查詢生成器直接查詢它會不會更有益? – MightyPork 2014-12-13 13:39:16
這就是我目前居住的地方。但仍然應該有辦法。 – apsdehal 2014-12-13 14:05:14