[SQL] Aggregates puzzle

2011-03-31 Thread Mark Fenbers
SQL gurus, I have a table with 4 columns: lid(varchar), value(float), obstime(datetime), event_id(integer) I want to find the MAX(value) and the time and date that it occurred (obstime) in each group of rows where the lid and event_id are the same. What I have works correctly in identifyin

Re: [SQL] Aggregates puzzle

2011-03-31 Thread Ozer, Pam
Try this. Once you know the value you want you have to join back to find the time of that value. Select f.Lid, F.Value,F.event_id, f.obstime From ( SELECT lid, MAX(value) As Value, event_id FROM flood_ts GROUP BY lid, event_id )sub Join flood f On sub.Value=f.value and f.lid=sub.lid and sub.event