title: Adding another column based on different criteria (SQL-server)
body: <p>I do quite a bit of data analysis and use SQL on a daily basis but my queries are rather simple, usually pulling a lot of data which I thereafter manipulate in excel, where I'm a lot more experienced. </p>
  
  <p>This time though I'm trying to generate some Live Charts which have as input a single SQL query. I will now have to create complex tables without the aid of the excel tools I'm so familiar with.</p>
  
  <p>The problem is the following:</p>
  
  <p>We have telesales agents that book appointments by answering to inbound calls and making outbound cals. These will generate leads that might potentially result in a sale. The relevant tables and fields for this problem are these:</p>
  
  <pre><code>Contact Table
  Agent
  
  Sales Table
  Price
  OutboundCallDate
  </code></pre>
  
  <p>I want to know for each telesales agent their respective Total Sales amount in one column, and their outbound sales value in another.</p>
  
  <p>The end result should look something like this: </p>
  
  <pre>
  +-------+------------+---------------+
  | Agent | TotalSales | OutboundSales |
  +-------+------------+---------------+
  | Tom   |      30145 |             0 |
  | Sally |      16449 |          1000 |
  | John  |      10500 |           300 |
  | Joe   |      50710 |             0 |
  +-------+------------+---------------+
  </pre>
  
  <p>With the below SQL I get the following result:</p>
  
  <pre><code>SELECT contact.agent, SUM(sales.price)
  FROM contact, sales
  WHERE contact.id = sales.id
  GROUP BY contact.agent   
  </code></pre>
  
  <pre>
  +-------+------------+
  | Agent | TotalSales |
  +-------+------------+
  | Tom   |      30145 |
  | Sally |      16449 |
  | John  |      10500 |
  | Joe   |      50710 |
  +-------+------------+
  </pre>
  
  <p>I want to add the third column to this query result, in which the price is summed only for records where the <code>OutboundCallDate</code> field contains data. Something a bit like (where <code>sales.OutboundCallDate</code> is Not Null)</p>
  
  <p>I hope this is clear enough. Let me know if that's not the case.</p>