0

在这个表中,当一个条目被输入2条记录到同一个表中时,它们可以与字段aref相关联,因为它们是相同的。

在 2 条记录之一中,bda 始终为空白字段,但其他记录中始终包含 bda。我需要把这个 bda 和剩下的数据一起拿出来

有人可以帮我对这个查询进行排序吗,这是我到目前为止所拥有的

SELECT ada,bda,sum(adur) / 60 as atime ,count(adur) as calls  
FROM cr_cdr 
WHERE script_res = 'sam0000' 
    AND adetdate BETWEEN CAST('2012-06-11 00:00:00 AM' AS datetime) 
    AND CAST('2012-06-11 11:59:59 PM' AS datetime) 
GROUP BY ada,bda
4

1 回答 1

0

您可以尝试将表连接到自身。像这样的东西:

SELECT c1.ada,c2.bda / 60 as atime ,count(c1.adur) as calls  
FROM 
cr_cdr c1
INNER JOIN
cr_cdr c2
ON( c1.aref = c2.aref )
WHERE 
c2.bda IS NOT NULL 
    AND c1.script_res = 'sam0000' 
    AND c1.adetdate BETWEEN CAST('2012-06-11 00:00:00 AM' AS datetime) 
    AND CAST('2012-06-11 11:59:59 PM' AS datetime) 
GROUP BY aref
于 2012-06-13T02:46:31.670 回答