Skip to content
Advertisement

Create query to get count of uncompleted calls

There is table waiter_log as

Call with call-id ‘f27de4f’ started in 9010 and finished in 9003 because there is a record with proceed_wait = 0 for call-id=’f27de4f’
Call with call-id ‘asdf231′ started in 9010, still proceed in 9002 and not finished yet because there is no record with proceed_wait = 0 for call-id=’asdf231’ Similarly for call with call-id ‘rete125’ there is no record with proceed_wait = 0 and this call is not completed too. So,for queue 9010 query result should be 2 (count of uncompleted calls) For 9003 result should be 0 , because all calls for 9003 (‘a7rf5gs’ and ‘qawe234′) are completed. For 9004 result should be 1 because there is no record with proceed_wait = 0 for call with call-id ’49c43ad’.

How to create a query to get count on uncompleted calls as:

UPD: Here i updated my question Create query to get count of uncompleted calls group by 2 fields

Advertisement

Answer

Here’s another method that works without correlated subqueries or window functions:

For each row w1, try to find another row w2 with the same call_id and a 0 indicating the call is complete. Using a LEFT OUTER JOIN, we can test for cases where no w2 row exists for a given call_id.

Then do another join to a hypothetical row w3 with the same call_id and a lesser ast_num_curr value. Again, using outer join, we can check that no such row exists. This means w1 must have the least value for ast num for that call_id.

Output:

To get the counts per queue_num_curr, wrap the query above in a derived-table subquery, and do the count in the outer query:

Output:

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