将简单的mysql查询转换为laravel 5.1查询构建器

时间:2016-04-18 14:18:10

标签: sql laravel laravel-5 laravel-5.1 query-builder

请任何人帮我在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

1 个答案:

答案 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);