title: SQL How to do a conditional sum by distinct id?
body: <p>Suppose you have result set such as:</p>
  
  <pre><code>DATE          ID    cost    
  ---------------------------------------
   01/01/2011    1     10      
   01/01/2011    1     10      
   01/01/2011    2     10      
   01/01/2011    2     10      
  </code></pre>
  
  <p>I want a way to sum the values on cost but only once for every distinct ID so that when i group by date I get a result such as</p>
  
  <pre><code>DATE            cost
  </code></pre>
  
  <hr>
  
  <pre><code>01/01/2011         20
  </code></pre>
  
  <p>I first tried something like </p>
  
  <pre><code>    sum(distinct cost) 
  </code></pre>
  
  <p>but that of curse only returns 10
  I also tried:</p>
  
  <pre><code>sum(case when distinct id then cost else 0 end)
  </code></pre>
  
  <p>but that is not a functional query.</p>