有谁知道如何解决此错误?这个sql工作正常,但对于'cumulinvoiced'分区功能。我正在尝试添加累计总数,但它似乎不适用于内联视图。
SELECT a.mois, a.supid, a.status, COUNT (a.status),
SUM (COUNT (a.status) OVER (ORDER BY a.status, a.supid, a.dossier, a.mois)) cumulinvoiced
from (SELECT TO_CHAR (impdate, 'YYYYMM') mois,
benefit#sup_inv_id supid,
SUBSTR (si_benstatus, 1, 1) status,
files#fil_secid dossier
FROM sbbenefit
WHERE benefit#sup_inv_id = 30515
AND SUBSTR(si_benstatus, 1, 1) = '2'
GROUP BY TO_CHAR (impdate, 'YYYYMM'), benefit#sup_inv_id ,SUBSTR (si_benstatus, 1, 1), files#fil_secid) a
GROUP BY a.mois, a.supid, a.status
order BY a.supid, a.mois , a.status
答案 0 :(得分:6)
汇总COUNT
应该是分析SUM
的参数,反之亦然:
SELECT a.mois, a.supid, a.status, COUNT (a.status),
SUM (COUNT (a.status)) OVER (ORDER BY a.status, a.supid, a.dossier, a.mois) cumulinvoiced
from (SELECT TO_CHAR (impdate, 'YYYYMM') mois,
benefit#sup_inv_id supid,
SUBSTR (si_benstatus, 1, 1) status,
files#fil_secid dossier
FROM sbbenefit
WHERE benefit#sup_inv_id = 30515
AND SUBSTR(si_benstatus, 1, 1) = '2'
GROUP BY TO_CHAR (impdate, 'YYYYMM'), benefit#sup_inv_id ,SUBSTR (si_benstatus, 1, 1), files#fil_secid) a
GROUP BY a.mois, a.supid, a.status
order BY a.supid, a.mois , a.status
答案 1 :(得分:0)
分析和分组不一定能够协同工作。如果您首先执行分组,然后对该结果执行分析查询,我认为它应该有效:
SELECT mois, supid, status, status_count,
SUM (status_count OVER (ORDER BY a.status, a.supid, a.dossier, a.mois)) cumulinvoiced
from
(SELECT a.mois, a.supid, a.status, COUNT (a.status) status_count
from
(
SELECT
TO_CHAR (impdate, 'YYYYMM') mois,
benefit#sup_inv_id supid,
SUBSTR (si_benstatus, 1, 1) status,
files#fil_secid dossier
FROM sbbenefit
WHERE benefit#sup_inv_id = 30515
AND SUBSTR (si_benstatus, 1, 1) = '2'
GROUP BY
TO_CHAR (impdate, 'YYYYMM'),
benefit#sup_inv_id ,
SUBSTR (si_benstatus, 1, 1),
files#fil_secid
) a
GROUP BY
a.mois, a.supid, a.status
)
order BY
supid, mois , status