请任何人帮我在laravel5.1中进行此查询:
SELECT sum(orders.price) - (select sum(orders.price)
FROM orders INNER JOIN articles ON articles.id = orders.article_id
WHERE articles.forSale = false)
FROM orders INNER JOIN articles ON articles.id = orders.article_id
e articles.forSale=true
答案 0 :(得分:1)
我明白了:
$query = "select (sum(orders.price) -
(select sum(orders.price) from orders
inner join articles on articles.id = orders.article_id
where articles.forSale = false)
) as p1 from orders
inner join articles on articles.id = orders.article_id
where articles.forSale = true";
return \DB::select($query);