mysql - 在 postgres 的不同列中获取联合的输出

标签 mysql sql-server postgresql

我在一家拨号器公司工作,我们有一个调用历史记录表,其中有不同的列。

现在我想获取一个可以计算的输出:

已接通的外拨电话总数

Select count(*) 
from call_history 
where system_disposition = 'CONNECTED' and call_type = 'OUTBOUND' 

系统检测到的 AMD 总数

Select count(*) 
from call_history 
where system_disposition = 'CONNECTED'   

AGent 检测到的 AMD 总量

Select count(*) 
from call_history 
system_disposition='CONNECTED' and call_id in (
    select call_id 
    from udh 
    where disposition_code = 'Answering machine'
)

现在,如果我使用 union 命令,所有结果都会出现在一列中,并且使用交叉联接会给出重复输出,即限制 2 给出每个条目两次的输出。

请帮助我进行一个查询,该查询可以告诉我:

出站连接总数 | AMD 系统 | AMD 代理 |泄漏为(AMD 代理/(总计)

最佳答案

您可以合并结果并在单独的列中选择每个结果,如下所示:

Select sum(r1) as result1, sum(r2) as redult2, sum(r3) as result3 from(
Select count(*) as r1, 0 as r2,0 as r3 from call_history where system_disposition='CONNECTED' and call_type='OUTBOUND'
Union
Select 0 as r1,count(*) as r2, 0 as r3 from call_history where system_disposition='CONNECTED')
Union
Select 0 as r1, 0 as r2,count(*) as r3 from call_history system_disposition='CONNECTED' and call_id in (select call_id from udh where disposition_code='Answering machine')
)

关于mysql - 在 postgres 的不同列中获取联合的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41346447/

相关文章:

ruby-on-rails - 使用关系数据库

MySQL REPAIR TABLE 由于空间问题而停止

mysql - Drupal 7 中 MySQL 转储导入时出现 AWS S3 错误

php - Mysql 在插入时抛出错误

sql - 为什么这个 T-SQL 会重复结果

sql-server - 在 SQL Server 中,如何将多个 .trc 文件移动/导入到跟踪表

PostgreSQL : Update column with same vaue

mysql - 如何将 datediff 和 curdate() 从 MySql 转换为 PostgreSQL

php - 如何选择字段数组在一行中显示或在一行中显示json

SQL Pivot on 条件计数