使用sum语句时按功能分组问题

时间:2019-05-23 02:47:18

标签: sql oracle

我将sum语句添加到case语句及其触发ORA-00937的情况:不是单个组组函数错误。

 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;

ive试图重新编写我的分组依据,添加到分组依据,摆脱它,一切都没有运气...

我目前让它计算ABC的值...我希望它然后将ABC的AS WELL的差异量相加。我相信sum语句是正确的,但会触发ORA错误...有什么建议...?

1 个答案:

答案 0 :(得分:1)

我已调整并在脚本中添加注释。可能是因为这并不能直接为您提供所需的输出(您需要进行更多调整),但这将引导您到达目的地:)

Genre: [
  { ID: "1", Title: "English", StudySubject: { "edges": [ { "node": { "ID": "4", "Title": "English",}}]}},
  { ID: "2", Title: "Maths", StudySubject: { "edges": [ { "node": { "ID": "4", "Title": "Maths",}}]}},
]