Skip to content
Advertisement

Select within grouped query to return last record of that group

I have a table which stores events along with event type and booking ID’s, my goal is to group the BookingID and return the first EventDate, the last EventDate and the last BC_EventType

At the moment I have this SQL:

Which returns something along the lines of:

This is great, however I need a column which displays the LAST BC_EventType ID, so in theory it would be where [BC_Event] = Max_Date. How would I do this?

Advertisement

Answer

One method is conditional aggregation:

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