Ein Ansatz ist, Ihre Tabelle gegen eine aggregierte Unterabfrage zu verknüpfen, die die früheste call_time pro call_id unter den unfertigen Anrufen findet. Ein Anruf gilt als unfertig, wenn er keine Zeile hat, in der proceed_wait = 0 ist.
select t.queue_num_curr, t.ast_num_curr, count(*) from mytable t inner join ( select call_id, min(call_time) call_time from mytable group by call_id having max(proceed_wait = 0) = 0 ) tmin on tmin.call_id = t.call_id and tmin.call_time = t.call_time group by t.queue_num_curr, t.ast_num_curr order by t.queue_num_curr, t.ast_num_curr queue_num_curr | ast_num_curr | count(*) -------------: | -----------: | -------: 9004 | 2 | 1 9010 | 2 | 2 9010 | 3 | 1 9010 | 5 | 1
Eine Anmerkung: In den Ergebnissen sollte queue_num = 9004 wahrscheinlich ast_num = 2 statt 1 anzeigen, da 1 zur call_id 49c43ad gehört.