title: Get last record in each group and SUM some of them
body: <p>i have a problem with sql query to mysql to take the last record in each group and sum some field in one query.i have a table:</p>
  
  <pre><code>name        date    interested  made_call
  andrew.h    2011-02-04      10        10
  andrew.h    2011-02-11      20        10
  andrew.h    2011-02-13      2         10
  sasha.g  2011-02-11      5         20
  sasha.g  2011-02-12      5         1
  </code></pre>
  
  <p>i need to sum made_call column grouping by name and return the last record from interested.
  here what i want to get in result:</p>
  
  <pre><code>name        date    interested  made_call
  andrew.h    2011-02-13      2         30
  sasha.g  2011-02-12      5         21
  </code></pre>
  
  <p>i tried to get result with this query</p>
  
  <pre><code>SELECT a.name,a.date,a.interested,sum(made_call) as made_call
  FROM `resultboard` a 
  WHERE a.attendence = 1 
  AND NOT EXISTS (select 1 from resultboard where name = a.name
         and id &gt; a.id and attendence = 1)
  GROUP BY name
  </code></pre>
  
  <p>but in result i  got</p>
  
  <pre><code>  andrew.h  2011-02-13      2         10
    sasha.g    2011-02-12      5         1
  </code></pre>
  
  <p>so the query didnot sum, just return the last record from group
  help)</p>