我的MySQL数据库中有一个表,其中包含以下列:
我想在以下查询中选择事件为'ENTERQUEUE'的所有行:
SELECT count(*)
FROM voipnow.ast_queue_log
WHERE queuename = '0536*401'
AND DATE(time) = '2014-03-07'
AND event = 'ENTERQUEUE'
ORDER BY time DESC;
但我只想显示事件列不等于CONNECT
的行数,其中callid
等于上述查询中的callid
列
答案 0 :(得分:0)
尝试:
SELECT count(*)
FROM voipnow.ast_queue_log
WHERE queuename = '0536*401'
AND DATE(time) = '2014-03-07'
AND event <> 'CONNECT'
and callid not in (SELECT callid
FROM voipnow.ast_queue_log
WHERE queuename = '0536*401'
AND DATE(time) = '2014-03-07'
AND event = 'ENTERQUEUE')
ORDER BY time DESC;
答案 1 :(得分:0)
您的描述留有解释空间。我把它读成:
“没有行存在同一个callid和event ='CONNECT'”
SELECT count(*)
FROM voipnow.ast_queue_log v1
WHERE queuename = '0536*401'
AND date(time) = '2014-03-07'
AND event = 'ENTERQUEUE'
AND NOT EXISTS (
SELECT 1
FROM voipnow.ast_queue_log v2
WHERE v2.callid = v1.callid
AND v2.event = 'CONNECT'
)