Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何除以别名?_Sql_Oracle_Oracle11g - Fatal编程技术网

Sql 如何除以别名?

Sql 如何除以别名?,sql,oracle,oracle11g,Sql,Oracle,Oracle11g,当我运行下面的查询时,我得到一个ORA-00937错误 select apex_utilities.get_invtype(o_code) ,count(c.id) as "Case Count" ,round(sum(billable_time/3600),2) as "Time(hrs)" ,round(sum(billable_time/count(c.id)),2) as "AHT(secs)" from myTable c where c.date_created bet

当我运行下面的查询时,我得到一个ORA-00937错误

select apex_utilities.get_invtype(o_code)
,count(c.id) as "Case Count"
,round(sum(billable_time/3600),2) as "Time(hrs)"
,round(sum(billable_time/count(c.id)),2) as "AHT(secs)"
from        myTable c
where c.date_created between :p31_period_start and add_months(:p31_period_start,1)
group by rollup(apex_utilities.get_invtype(o_code));
如果我把这行注释掉

    ,round(sum(billable_time/count(c.id)),2) as "AHT(secs)"
它按预期运行,不显示此列

我如何让它运行,包括这条线?如果我在之前将计费时间添加到组中,那么输出是不正确的,因为我得到了许多行,因为它将所有计费时间以及invtype分组。此外,我必须从行中删除“SUM”以使其运行

我正在寻找的输出类似于以下内容

invtype    CaseCount    Time(Hrs)    AHT(secs)
CDCW          1234       308:53:45   909.56
CBCB          100        24:56:34    109.24

看起来你想要的其实是:

 ,round(sum(billable_time)/count(c.id),2) as "AHT(secs)"` 

我怀疑这是因为您正在聚合中聚合。如果你真的想这样做,那么你可能需要一个子查询来获得
count(c.id)
,这样你就可以在
SUM(bilable\u time,count\u of c\u id)
位的聚合中应用它

您需要将该计数移出子查询。为了清楚起见,我对这里的总和也做了同样的处理:

 with cteTable as
 (
  select apex_utilities.get_invtype(o_code) invtype
        ,count(c.id)                        casecount
        ,sum(billable_time)                 totaltime
    from myTable c
   where c.date_created between :p31_period_start and add_months(:p31_period_start,1)
group by rollup(apex_utilities.get_invtype(o_code))
 )
 select invtype 
       ,casecount                    "Case Count"
       ,round(totaltime/3600,2)      "Time(hrs)"
       ,round(totaltime/casecount,2) "AHT(secs)"
   from cteTable;