Use GROUP_COUNT() function
This thread would be helpful Limit Concurrent Calls per DID using one peer in sip.conf