title: How to sum up a field depending on an other field value?
body: <p>I am developing a small stored procedure on SQL server 2008. I have little knowledge on SQL queries, but enough to achieve simple tasks. However I came up with a problem I can't solve myself. Before I start explaining my problem, please pardon me if I spell a SQL query-word wrong because I am not a native English speaker.</p>
  
  <p>I have 4 fields(CSV representation):</p>
  
  <pre><code>ID, NAME, VALUES, ANSWER
  25, Tom , 2400 , 0                
  25, Tom , 600 , 0                
  25, Tom , 500 , 1                
  25, Tom , 300 , 1                
  27, Jerry, 100, 0                
  27, Jerry, 20, 1                
  27, Jerry, 60, 1                
  27, Jerry, 2000, 0     
  </code></pre>
  
  <p>What I want to do is group by the selection by its <code>ID</code> and <code>NAME</code>, Sum up it's values in a field named <code>positive when ANSWER = 1</code> and <code>negative when ANSWER = 0</code>.</p>
  
  <pre><code>ID, NAME, SUM, NEGATIVE, POSITIVE
  25, Tom, 3000, 800                   
  27, Jerry, 2100, 80
  </code></pre>
  
  <p>I Guess my question has been asked several times, but I wasn't able to find anything about it, probably because I am using the wrong terms. Anyway if someone could help that would save me a lot of time.</p>