0

Please any one may help me to make this query in 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
4
  • 1
    Thanks @manix for editing it :) Commented Apr 18, 2016 at 14:30
  • Please see updates Commented Apr 18, 2016 at 14:46
  • your answer is just using Query Builder, not eloquent. You should update the question to remove references to Eloquent if you don't need that in the solution. Commented Apr 18, 2016 at 20:32
  • 1
    @SlateEntropy thanks for note, it's done Commented Apr 18, 2016 at 20:49

1 Answer 1

1

I got it :

    $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); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.