title: SQL Combining MAX and SUM
body: <p>So I have one SQL table that contains the below columns:</p>
  <pre><code>License# - int
  Name - char(255)
  ActivityDate - datetime
  FundsIn - money,null
  </code></pre>
  <p>There are ~2800 unique License numbers and will have numerous FundsIn each day. I am trying to find the last date there was activity (ActivityDate) and the sum of all of the FundsIn on that MAX ActivityDate.</p>
  <p>Below is a query I've been trying to modify to get it to work, but it is returning the sum of the license number across all dates and not just the MAX date.</p>
  <pre><code>Select License, Name, MAX(ActivityDate), FundsIn
  From (
      Select License, Name, ActivityDate, SUM(FundsIn) as Funds_In
      From Table1
      group by License, Name, ActivityDate
  ) foo
  group by License, Name, FundsIn
  </code></pre>
  <p>I know the issue with the current query is that it is grouping the entire dataset of FundsIn, but I can't figure out how to limit the sum of FundsIn to only the MAX date. Any help would be appreciated.</p>
  <p>Sample Date</p>
  <pre><code>License   Name   ActivityDate   FundsIn
  123       A      8/29/2020      40
  123       A      8/29/2020      60
  123       A      8/29/2020      80
  123       A      8/29/2020      55
  123       A      8/30/2020      10
  123       A      8/30/2020      15
  123       A      8/30/2020      12
  123       A      8/30/2020      60
  123       A      8/30/2020      70
  234       B      8/29/2020      12
  234       B      8/29/2020      15
  234       B      8/29/2020      19
  234       B      8/29/2020      22
  234       B      8/29/2020      33
  234       B      8/30/2020      13
  234       B      8/30/2020      78
  234       B      8/30/2020      28
  234       B      8/30/2020      34
  234       B      8/30/2020      46
  </code></pre>
  <p>In the above data the query would return the below</p>
  <pre><code>License   Name   ActivityDate   FundsIn
  123       A      8/30/2020      167
  234       B      8/30/2020      199
  </code></pre>