简体   繁体   English

表的SELECT计数,其中列为CONNECT,但与其他相关列相关的其他行没有特定值

[英]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数据库中有一个表,该表中包含列:

  • callid 呼号
  • event 事件

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.

相关问题 根据MySQL和PHP中其他表的列中的最高值选择行 - Select rows based on the highest value in a column of an other table in MySQL & PHP 对其他表上的Count(*)相关行的语句 - Statement to Count(*) related rows on other table Laravel Eloquent:选择相关表中具有x的位置,但从相关表中排除某些行 - Laravel Eloquent: Select where related table has x, but exclude certain rows from related table 选择两行具有相同列值的位置并回显它们 - Select where two rows have the same column value and echo them 从表中选择*,其中column =值^ column2 =值 - select * from table where column = value ^ column2= value 我们可以从一个表中选择一个吗?我们有多行具有相同的列名吗? - Can we SELECT ONE FROM (a table) WHERE we have multiple rows of same column names? 从与其他标准匹配的行中选择特定列中具有最低值的行 - Select the rows with lowest value in specific column from those who match the other critarias PostgreSQL SELECT WHERE IN子查询具有来自其他列的自身条件 - PostgreSQL SELECT WHERE IN Subquery with its own condition from other column MySQL - 根据用户的选择选择列 &#39;Name&#39; 列 &#39;id&#39; 和 &#39;parent&#39; 中的行彼此相等 - MySQL - Select Column 'Name' according to user's choice Where rows in Column 'id' and 'parent' equal each other SELECT sql语句,该语句从表中检索一行,并从另一表中检索许多相关行 - SELECT sql statement that retrieves one row from a table and many related rows from other table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM