1

在查看链接中的图片时,我需要平均内爆单位和总和,我将在下面显示的结果下方附加我的代码。这几天我一直在寻找这个问题的答案。我担心我可能会试图在我的头上编码一点。

   SELECT A.to_load_id                                   AS "Cases", 
   A.from_qty - A.to_qty                          AS "Imploded Units", 
   ( A.from_qty - A.to_qty ) * Nvl(SUM(p.qty), 1) AS "Exploded Units", 
   A.wskusku                                      AS "Sku's", 
   A.wave                                         AS "Wave", 
   A.from_loc                                     AS "Processed Location", 
   A.free_form_text                               AS "Zone" ,

   FROM   audits A, 
   prepack P 
   WHERE  A.from_loc LIKE 'S%' 
   AND A.to_loc = A.from_loc 
   AND free_form_text IN ( '01', '02', '03', '04', 
                           '05', '06', '07', '08', 
                           '09', '10', '11', '12', 
                           '13', '14' ) 
   AND A.wskusku = p.sku (+) 
   AND A.from_load_id = '42419472' 
   AND A.wave in ('WC055193','','','','','','','','','')
   AND To_date(Substr(a.date_wms, 1, 12), 'YYYY/MM/DD HH24:MI') >= 
       SYSDATE - 4 
   GROUP  BY A.to_load_id, 
      A.from_qty, 
      A.to_qty, 
      P.qty, 
      A.wskusku, 
      A.wave, 
      A.from_loc, 
      A.free_form_text 
4

1 回答 1

1

您需要使用avg()/sum()不是 GROUP BY聚合中涉及的列:

SELECT A.to_load_id                                    AS "Cases"
      ,avg(A.from_qty - A.to_qty)                      AS "Imploded Units"
      ,sum(A.from_qty - A.to_qty) * Nvl(SUM(P.qty), 1) AS "Exploded Units"
      ,A.wskusku                                       AS "Sku's"
      ,A.wave                                          AS "Wave"
      ,A.from_loc                                      AS "Processed Location"
      ,A.free_form_text                                AS "Zone"
FROM   audits A 
JOIN   prepack P ON P.sku (+) = A.wskusku
WHERE  A.from_loc LIKE 'S%' 
AND    A.to_loc = A.from_loc 
AND    A.free_form_text IN ( '01', '02', '03', '04', 
                           '05', '06', '07', '08', 
                           '09', '10', '11', '12', 
                           '13', '14' )
AND    A.from_load_id = '42419472'
AND    A.wave in ('WC055193','','','','','','','','','')
AND    To_date(Substr(A.date_wms, 1, 12), 'YYYY/MM/DD HH24:MI') >= SYSDATE - 4
GROUP  BY A.to_load_id, 
      ,A.wskusku
      ,A.wave
      ,A.from_loc
      ,A.free_form_text

不知道为什么你多个"Exploded Units",但不是"Imploded Units"。我复制了你那里的东西。

于 2012-12-09T17:40:47.233 回答