Skip to content
Advertisement

Using sum with multiple dates but keeping only the latest date

I have a table called Prospect that looks like this and I’m trying to SUM the value so that I have only 1 column for GEORGIA, ALABAMA,TEXAS and the date kept in the date field be the latest date entry.

I would like to have a resultset that looks like this

This is what I’ve tried, but it is not summing properly:

Thanks for any feedback

Advertisement

Answer

I think you want:

  1. Use max to get the latest date.
  2. group by sight only, as for all other columns you want aggregated amounts.

Do really need so much casting? If you have used the correct datatypes in your table definition then the following will work:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement