1

我有一个查询,我试图通过减去一列的总数来获得一列 - 其他但我收到错误。这就是我正在做的

select LOSA_APP.app_ref_no AS "App.Ref.No.", 
       CODE_BRANCH.branch_name AS "Business Unit",
       ....
        sum(LOSA_FACILITIES.amt_appr) - DOCS_DISB_SIGN_OFF_LOG.sign_off_amt AS "Amount Not Disbursed",
       ...
from
    losa_app LOSA_APP
INNER JOIN
    code_branch CODE_BRANCH
ON
    LOSA_APP.attend_branch = CODE_BRANCH.branch_id
...
where 
    LOSA_APP.app_status='A'; -- Application Status in {‘accepted’} 

但我收到错误

ORA-00937: not a single-group group function
00937. 00000 -  "not a single-group group function"
*Cause:    
*Action:
Error at Line: 1 Column: 8

我怎样才能完成这件事?

4

2 回答 2

2

ORA-00937: 不是单组组函数

原因: 一个 SELECT 列表不能同时包含一个组函数,例如 AVG、COUNT、MAX、MIN、SUM、STDDEV 或 VARIANCE,以及​​一个单独的列表达式,除非单独的列表达式包含在 GROUP BY 子句中。

行动:从 SELECT 列表中删除组函数或单个列表达式,或添加一个 GROUP BY 子句,其中包括列出的所有单个列表达式。

https://www.google.com/search?q=ORA-00937%3A+not+a+single-group+group+function&oq=ORA-00937%3A+not+a+single-group+group+function&sugexp=铬,mod=6&sourceid=chrome&ie=UTF-8

select LOSA_APP.app_ref_no AS "App.Ref.No.", 
   CODE_BRANCH.branch_name AS "Business Unit",
   ....
    sum(LOSA_FACILITIES.amt_appr) - DOCS_DISB_SIGN_OFF_LOG.sign_off_amt AS "Amount Not Disbursed",
   ...
 from
   losa_app LOSA_APP

 INNER JOIN
   code_branch CODE_BRANCH
 ON
   LOSA_APP.attend_branch = CODE_BRANCH.branch_id
   ...
 GROUP BY LOSA_APP.app_ref_no, LOSA_APP.app_ref_no
 HAVING  LOSA_APP.app_status='A'; -- Application Status in {‘accepted’} 
于 2012-11-30T06:45:49.627 回答
0

如果每个 amt_appr 都有一个 sign_off,请尝试此操作:

sum(LOSA_FACILITIES.amt_appr - DOCS_DISB_SIGN_OFF_LOG.sign_off_amt)

或者这个技巧,其中重复值的 AVG 是重复值:

sum(LOSA_FACILITIES.amt_appr) - AVG(DOCS_DISB_SIGN_OFF_LOG.sign_off_amt)
于 2012-11-30T06:40:15.653 回答