我想让它加总ABC的价值

时间:2019-05-21 02:17:16

标签: oracle

        select distinct
  dsp_sku
,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 = 'VP521X' then 'B'
    when dsp_sku = 'FT6009' then 'B'
    when dsp_sku = '125037' then 'B'
  when dsp_sku = 'CG925' then 'C'
    when dsp_sku = 'SPGR101351' then 'C'
    when dsp_sku = 'CL14MG' then 'C'
when dsp_sku = '603011825' then 'D'
    when dsp_sku = '603011827' then 'D'
    when dsp_sku = '603011828' then 'D'
    else null
  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 > '&StartDate'
--and dsp_sku = '&SKU'
  --and not im.srl_nbr_reqd = 4
  --and EXPTD_QTY = 0
  --and actl_invn_qty = 0

我尝试了总结语句,但没有任何建议? 这是查询的较小版本,原始查询在声明时具有更多的ABC情况行。

2 个答案:

答案 0 :(得分:0)

如果我对您的理解正确,那将会是

  SELECT dsp_sku,
         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 = 'VP521X' THEN 'B'
            WHEN dsp_sku = 'FT6009' THEN 'B'
            WHEN dsp_sku = '125037' THEN 'B'
            WHEN dsp_sku = 'CG925' THEN 'C'
            WHEN dsp_sku = 'SPGR101351' THEN 'C'
            WHEN dsp_sku = 'CL14MG' THEN 'C'
            WHEN dsp_sku = '603011825' THEN 'D'
            WHEN dsp_sku = '603011827' THEN 'D'
            WHEN dsp_sku = '603011828' THEN 'D'
            ELSE NULL
         END
            AS abc_value,                                                   --
         COUNT (*)                                                    --> this
    FROM ...
GROUP BY dsp_sku,
         DECODE (cc.stat_code,
                 '0', 'Unprocessed',
                 '90', 'Processed',
                 '99', 'Expired'),
         TRUNC (cc.create_date_time),
         CASE
            WHEN dsp_sku = 'EGIA60AMT' THEN 'A'
            WHEN dsp_sku = 'LF1937' THEN 'A'
            WHEN dsp_sku = '980X3ENDIUU' THEN 'A'
            WHEN dsp_sku = 'VP521X' THEN 'B'
            WHEN dsp_sku = 'FT6009' THEN 'B'
            WHEN dsp_sku = '125037' THEN 'B'
            WHEN dsp_sku = 'CG925' THEN 'C'
            WHEN dsp_sku = 'SPGR101351' THEN 'C'
            WHEN dsp_sku = 'CL14MG' THEN 'C'
            WHEN dsp_sku = '603011825' THEN 'D'
            WHEN dsp_sku = '603011827' THEN 'D'
            WHEN dsp_sku = '603011828' THEN 'D'
            ELSE NULL
         END;

答案 1 :(得分:0)

您没有要累加的数字列,因此我假设您希望计算每种abc_value的数量,那么您只需要进行查询并将其嵌套在另一个查询中即可执行GROUP BY

SELECT abc_value,
       COUNT(*) AS num_abc_values
FROM   (
  <your_large_query>
)
GROUP BY abc_value