Laravel中针对以下查询的备用查询是什么?
SELECT t1.siteName, COALESCE(t2.fee, 0) FROM sites t1
LEFT JOIN
(
SELECT site_id, sum(fee) as fee
FROM tickets
WHERE ticketdate BETWEEN '2017-01-01' AND '2017-03-31'
GROUP BY site_id
) t2
ON t1.id = t2.site_id
ORDER BY t2.fee DESC
答案 0 :(得分:0)
We need to show all sites name and their total fee in a given period, when total fee is 0 against any site, it shows 0. we have correct sql query for it, but we need to implement this query in Laravel. So, we need alternate query in laravel for given below query: Tables: sites(id, siteName, created_at, updated_at) tickets(id, site_id, fee, ticketdate, created_at, updated_at) Models: Site, Ticket