我的数据库中有一个包含列的表:
我正在运行此查询:
SELECT COUNT(DISTINCT callid) as r FROM voipnow.ast_queue_log
WHERE queuename = '0536*401'
AND time > '2014-03-19 15:38:00'
AND callid NOT IN (SELECT callid FROM voipnow.ast_queue_log
WHERE event = 'CONNECT'
OR event = 'ABANDON')
AND event = 'RINGNOANSWER'
显示CALLID列相同但没有行包含事件CONNECT
或ABANDON
或RINGNOANSWER
所以当调用者等待时,只有包含事件ENTERQUEUE
或RINGNOANSWER
这工作正常,但是当插入第一行时(使用事件ENTERQUEUE
),它应该显示1的计数,但它显示0,直到插入另一行事件RINGNOANSWER
答案 0 :(得分:1)
试试这个:
SELECT COUNT(DISTINCT callid) as r
FROM voipnow.ast_queue_log
WHERE queuename = '0536*401'
AND time > '2014-03-19 15:38:00'
AND callid NOT IN (SELECT callid FROM voipnow.ast_queue_log
WHERE event IN ('CONNECT', 'ABANDON', 'RINGNOANSWER'))