I have a table like so:
call_activity (
call_id TEXT,
activity_type TEXT,
activity_time TIMESTAMP,
PRIMARY KEY(call_id, activity_type, activity_time)
)
activity_type
may be one of about 9 different strings:
'started'
'completed' (about 5 variations on this)
'other' (these are the states that I want to display)
A call has a series of events, starting with 'started' and culminating in a completed event (one of 5 or so possible ones). I need a view of this with two columns: The first column must be the activity time of a call's 'started' event, the second column must be the most recent event for that call. This view must only have calls for which there is no completed event.
I have a set of nested joins on it, but they're slow as hell. I need a reasonably optimal view of this. Can anyone help me?