按字段SQL Oracle SUM()添加值

时间:2015-04-27 20:41:06

标签: sql sql-server oracle oracle11g

Supervisor   TalkTime  HoldTime   CallsHandle
    Agent1     400        20          5
    Agent1     360        30          2
    Agent1     200        21          5
    Agent2     150        15          4
    Agent2     120        10          5

我需要为每个代理添加Talktime。 Agent1 = 960 & Agent2 = 270 在Oracle BI SQL上,如何添加每个代理的所有TalkTime以在新字段中显示。我桌上有大约250名代理人。我也必须做以下公式: AHT =(TalkTime + HoldTime)/ CallsHandle

4 个答案:

答案 0 :(得分:0)

这是一个简单的group by语句。每个SQL课程或书籍的介绍都包含它。

SELECT supervisor, SUM(TalkTime+HoldTime) / SUM(CallsHandle) AS AHT
FROM yourtable
GROUP BY Supervisor

答案 1 :(得分:0)

select supervisor,sum(talktime),sum(holdtime),sum(callshandle),SUM(talktime+holdtime) / SUM(callshandle) as AHT
from table_name
group by supervisor

答案 2 :(得分:0)

要显示详细信息和总结,最好的方法是在分析版本中使用函数sum()

select supervisor, talktime, holdtime, 
    sum(TalkTime) over (partition by supervisor) talk_sum,
    sum((TalkTime + HoldTime)/CallsHandle) over (partition by supervisor) AHT
  from test
  order by supervisor;

SQLFiddle demo

SUPERVISOR   TALKTIME   HOLDTIME   TALK_SUM        AHT
---------- ---------- ---------- ---------- ----------
Agent1            400         20        960      323,2 
Agent1            360         30        960      323,2 
Agent1            200         21        960      323,2 
Agent2            150         15        270      67,25 
Agent2            120         10        270      67,25 

答案 3 :(得分:0)

从您的查询中我知道您只想在BI报告中添加此AHT,无需在其他表中插入此详细信息。请查看以下查询。

查询。

select SUPERVISOR,SUM(TALKTIME) AS Total_TalkTime
,SUM(HOLDTIME) as Total_HoldTime
,SUM(AHT) as AHT 
from 
(select Supervisor,TalkTime,HoldTime,CallsHandle
,(TalkTime+HoldTime)\CallsHandle AS AHT FROM TABLENAME) 
group by SUPERVISOR;