[英]SELECT count from table where column is CONNECT but other rows with related other column does not have a certain value
I have a table in my MySQL database which has columns: 我的MySQL数据库中有一个表,该表中包含列:
I want to select all rows where the event is 'ENTERQUEUE' which i am doing in the below query: 我想在以下查询中选择事件为“ 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;
But i only want to show the number of rows where the event column is not equal to CONNECT
where callid
is equal to the callid
column from the above query 但是我只想显示事件列不等于
CONNECT
的行数,其中callid
等于上述查询中的callid
列
Try: 尝试:
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;
Your description leaves room for interpretation. 您的描述留下了解释的空间。 I read it as:
我读为:
"where no row exists with the same callid and event = 'CONNECT'" “不存在具有相同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'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.