Hi All!
I need some help with a query - I'm using Firebird 2.1.
I have a table like:
RowID (primary key) | ActivityID | Duration | BilledAt
1 | 1 | 50 | 06.08.2010, 14:05:00.598
2 | 1 | 70 | 06.08.2010, 14:05:00.608
3 | 2 | 30 | 06.08.2010, 14:05:00.598
4 | 3 | 40 | 06.08.2010, 14:05:00.598
5 | 3 | 50 | 06.08.2010, 14:05:00.608
I'd like to get the Durations for each ActivityID BUT if there are more than one entries available with the same ActivityID, I need the get the one with the highest BilledAt value. (the most recent entry)
If I execute:
SELECT ActivityID, Max(BilledAt)
FROM BilledTime
GROUP BY ActivityID;
I'll get what I want without the Duration values. If I include the Duration column in the GROUP BY clause, then multiple ActivityIDs are selected.
Is there an elegant solution to this?
Thanks!