我正在尝试添加列中的所有值以获取该列的总数,任何人都知道这个技巧吗?
这是我的疑问:
select T.*,
sum(nvl(BIN1,0))+sum(nvl(BIN2,0))+sum(nvl((BIN3,0)) as TOTAL
from
(
SELECT CSM_FLASKS.FLASK_CODE,
MN_ASSAYS_STAGES.ASSAY_STAGE_ID,
VITRO_REP.TREATMENT_DOSE(CSM_FLASKS.GROUP_ID) AS TREATMENT_DOSE,
MN_RI_REP.FLASK_BIN_VALUE_BY_INDEX(MN_ASSAYS_STAGES.ASSAY_STAGE_ID, CSM_FLASKS.FLASK_ID, 1) AS BIN1,
MN_RI_REP.FLASK_BIN_VALUE_BY_INDEX(MN_ASSAYS_STAGES.ASSAY_STAGE_ID, CSM_FLASKS.FLASK_ID, 2) AS BIN2,
MN_RI_REP.FLASK_BIN_VALUE_BY_INDEX(MN_ASSAYS_STAGES.ASSAY_STAGE_ID, CSM_FLASKS.FLASK_ID, 3) AS BIN3,
MN_RI_REP.CBPI_FLASK(MN_ASSAYS_STAGES.ASSAY_STAGE_ID, CSM_FLASKS.FLASK_ID, 1, 2, 2) AS CBPI,
CSM_EXPERIMENTS.EXPT_CODE
FROM CSM_TREATMENT_GROUPS_EXPTS
INNER JOIN CSM_ASSAYS
ON CSM_ASSAYS.EXPT_ID = CSM_TREATMENT_GROUPS_EXPTS.EXPERIMENT_ID
INNER JOIN CSM_FLASKS
ON CSM_TREATMENT_GROUPS_EXPTS.GROUP_ID = CSM_FLASKS.GROUP_ID
INNER JOIN MN_ASSAYS
ON CSM_ASSAYS.ASSAY_ID = MN_ASSAYS.ASSAY_ID
INNER JOIN MN_ASSAYS_STAGES
ON MN_ASSAYS.MN_ASSAY_ID = MN_ASSAYS_STAGES.MN_ASSAY_ID
INNER JOIN CSM_EXPERIMENTS
ON CSM_EXPERIMENTS.EXPT_ID = CSM_TREATMENT_GROUPS_EXPTS.EXPERIMENT_ID
AND CSM_EXPERIMENTS.EXPT_ID = CSM_ASSAYS.EXPT_ID
WHERE CSM_ASSAYS.ASSAY_ID = 1000060
AND MN_ASSAYS_STAGES.STAGE_ID = 2
ORDER BY CSM_TREATMENT_GROUPS_EXPTS.ORDER_INDEX,
CSM_FLASKS.FLASK_ID,
CSM_FLASKS.IS_PLUS DESC
) T
错误:
ORA-00937:不是单组组功能
00937. 00000 - “不是单组小组的功能”
*原因:
*行动:
行错误:1列:9
答案 0 :(得分:3)
使用任何聚合函数时,您需要将非聚合字段添加到GROUP BY
子句中。因此,在您的列中,您需要列出SUM
子句中聚合函数GROUP BY
中未列出的字段。因此,您的查询应如下所示:
SELECT FLASK_CODE,
SUM(nvl(BIN1, 0)) + SUM(nvl(BIN2, 0)) + SUM(nvl((BIN3, 0)) AS TOTAL
FROM
(
...
) T
GROUP BY FLASK_CODE
这只是一个例子。但您必须确定在SELECT
子句中选择哪些字段,并且还需要在GROUP BY
子句中列出。
答案 1 :(得分:1)
试试这个: 如果您在单列中添加所有数据意味着:
select sum( column_name ) from table inner join .........;
最后你找到总数