HI all,
I'm trying to figure out how to get the maximum value of a field within a group; e.g. I want the record corresponding to the most recent site visit.
| ObjectID | Site_ID | SpecCode | SStatus | Mon_Date |
| 1 | A | Frog | OCCU | 1/1/1999 |
| 2 | A | Frog | UNOC | 1/4/1999 |
| 3 | A | Frog | OCCU | 5/2/2008 |
| 4 | B | Toad | UNOC | 3/6/2007 |
| 5 | B | Toad | OCCU | 9/5/2014 |
In this case, I want to return the max date for each site, returning records #3 and #5.
I'd like to be able to do it in either select by attribute or a search cursor.
I'm having trouble structuring my SQL clause(s) to make this happen.
How To: Select minimum and maximum values in the Select By Attributes window (esri.com)
This is my query I've tried for select by attribute:
(SpecCode = 'Toad' Or SpecCode = 'Frog') And
(SStatus = 'OCCU') And
(Mon_Date = (SELECT MAX(Mon_Date) from [Table Name] GROUP BY Site_ID))
I'd appreciate any pointers on this; I feel like it should be really easy and so far it hasn't been.