title: SQL join in SUM function issue
body: <p>I want to SUM t.amount, w.bStake and w.lStake (conditionally)</p>
  
  <p>from transactions t and wagers w.</p>
  
  <p>The amount should always be summed up and between back and profit should be a condition.</p>
  
  <pre><code>If w.Profit is positiv -&gt; t.Amount + w.Back
  
  If w.Profit is negativ -&gt; t.Amount + w.Profit
  </code></pre>
  
  <p>My code that I use until this point looks like this:</p>
  
  <pre><code>SELECT 
    b.Bookie, 
    (SELECT SUM(t.Amount) FROM Transactions t WHERE t.Bookie = b.id)
  FROM Bookie b
  </code></pre>
  
  <p>My tables are:  </p>
  
  <pre><code>Bookie:
  ------------
  Id : int (Primary Key)
  Bookie : varchar
  
  
  Transactions:
  -------------------
  Id : int (Primary Key)
  Date : date
  Bookie : int (Foreign Key)
  Amount : decimal 
  
  
  Wagers:
  Id : int (Primary Key)
  Profit : decimal
  Back : decimal
  Bookie : int (Foreign Key)
  </code></pre>
  
  <p>How can I solve this Issue? Or is it only possible if I restructure my database?
  Thanks a lot.</p>