title: SQL maxdate for each given year
body: <p>Searched through the posts found similar questions but was not able to translate answer(s) to solve for the issue I'm having.  The output of this selection should be account_id,  most recent wip_stmt_date in each calendar year with aggreated financials, some of which which I excluded from the data output below.  Any suggestions would be much appreciated. </p>
  
  <hr>
  
  <pre><code>SELECT a.account_id,
     a.wip_stmt_date,
     SUM(b."Cost to Complete") AS "Cost to Complete",
     SUM(b."Estimated Gross Profit") AS "Estimated Gross Profit",
     SUM(b."Earned Gross Profit") AS "Earned Gross Profit"
  
  FROM WIP a
     inner join (
  SELECT wip_id,
      SUM(wip_compl_cost) AS "Cost to Complete",
      SUM(est_gross_profit) AS "Estimated Gross Profit",
      SUM(earned_gross_profit) AS "Earned Gross Profit"
          FROM WIP_Detail GROUP BY wip_id
           ) b
  
   ON a.wip_id = b.wip_id
  
   WHERE year(a.wip_stmt_date) &gt; 2008 and account_id is not null
  
   GROUP BY a.account_id, a.wip_stmt_date
  </code></pre>
  
  <hr>
  
  <pre><code> account_id      wip_stmt_date        Cost to Complete
      400      1996-06-30 00:00:00.000     989704310 don't need
      400      1996-09-30 00:00:00.000    1168271446 don't need
      400      1996-12-31 00:00:00.000    1200403025
      400      1997-03-31 00:00:00.000    1232629057 don't need
      400      1997-06-30 00:00:00.000    1114344673 don't need
      400      1997-09-30 00:00:00.000    1304671991 don't need
      400      1997-12-31 00:00:00.000    1407410337
      400      1998-03-31 00:00:00.000    1549329678 don't need
      400      1998-09-30 00:00:00.000    1608083965
      400      1999-03-31 00:00:00.000    1663183272
      400      2000-03-31 00:00:00.000    1673019904
      400      2001-03-31 00:00:00.000    1828818751
      400      2002-09-30 00:00:00.000    2847506038 don't need
      400      2002-12-31 00:00:00.000    3366648755
  </code></pre>