【发布时间】:2019-05-23 02:47:17
【问题描述】:
我在 case when 语句中添加了 sum 语句,它触发了 ORA-00937: not a single-group group function 错误。
SELECT DISTINCT abc_value,
COUNT (*) AS num_abc_values
from (
select dsp_sku,
sum(case
when EXPTD_QTY <> ACTL_INVN_QTY then (EXPTD_QTY-ACTL_INVN_QTY)*(-1)
else null
end) as "Variance_"
,decode (cc.stat_code, '0', 'Unprocessed', '90', 'Processed', '99', 'Expired') as Status,
trunc(cc.create_date_time) CC_date,
case
when dsp_sku = 'EGIA60AMT' then 'A'
when dsp_sku = 'LF1937' then 'A'
when dsp_sku = '980X3ENDIUU' then 'A'
when dsp_sku = '186-0106' then 'A'
when dsp_sku = 'PM35MN02' then 'A'
when dsp_sku = 'SIGC60MT' then 'B'
when dsp_sku = 'GS833' then 'B'
when dsp_sku = '5.5 PED' then 'B'
when dsp_sku = 'L74' then 'B'
when dsp_sku = 'VLOCL2105' then 'B'
when dsp_sku = 'VLOCM0134' then 'C'
when dsp_sku = '8886471021V' then 'C'
when dsp_sku = 'SILSCLINCH46' then 'C'
when dsp_sku = 'YCN1800P' then 'D'
when dsp_sku = 'YCN1801P' then 'D'
when dsp_sku = 'Y-REFACH-X-E' then 'D'
when dsp_sku = 'ZL7777-0091' then 'D'
else 'Empty Location'
end as ABC_Value
from WH_GHC1.CYCLE_COUNT_HIST cc
left join item_master im on
im.sku_id = cc.sku_id
inner join locn_hdr lh on
lh.locn_id = cc.locn_id
where
cc.whse = 'PH3'
--and cc.stat_code in ('0','90') --stat_code: 0 is unprocessed, 90 is processed, 99 is expired
and cc.stat_code = 90
--and cc.stat_code = 0
--and cc.create_date_time between '&FromDate' and '&EndDate'
and cc.create_date_time between '&FromDate' and '&ToDate'
--and dsp_sku = '&SKU'
--and not im.srl_nbr_reqd = 4
--and EXPTD_QTY = 0
--and actl_invn_qty = 0
)
GROUP BY ABC_Value, Dsp_sku
--having count (Variance_) <>0;
我尝试重新编写我的 group by,添加到 group by,摆脱它,但都没有运气......
我目前有它计算 ABC 的值...我希望它然后将 ABC 的差异量相加。我相信 sum 语句是正确的,但会触发 ORA 错误...有什么建议吗...?
【问题讨论】:
-
您的子查询有一个聚合函数
sum(case when exptd_qty...),但没有group by子句。 -
我写这篇评论是因为我还不完全确定,但我相信你的 group by 应该包括你的整个 decode 语句。并且应该在子查询内
-
查询现在有效,但它为每个方差创建一行。它为每个数量和差异量做了一行,我希望它只是告诉我有多少。比如 a 的 5 个方差和 b 的 2 个方差,依此类推。有什么建议...?