我有一个查询,其中我试图通过减去一列的总数来获取列 - 其他但我收到错误。这就是我正在做的事情
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
我怎样才能完成这件事?
答案 0 :(得分:2)
ORA-00937:不是单组群组功能
原因: SELECT列表不能同时包含组函数,如AVG,COUNT,MAX,MIN,SUM,STDDEV或VARIANCE,以及单个列表达式,除非单个列表达式包含在GROUP BY子句中。
操作:从SELECT列表中删除组函数或单个列表达式,或添加包含列出的所有单个列表达式的GROUP BY子句。
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’}
答案 1 :(得分: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)