在做报表的时候,经常会用到分段统计数据,这时候,case就比较有用了:
小例子:
SELECT sh.dc_code, g.bg_code,
TO_CHAR (ship_date, 'MM') AS ship_date,
SUM
(CASE
WHEN 2 >= NVL (p.pdt_packingweight, 0)
THEN pl.picked_qty
ELSE 0
END
) AS weight1,
SUM
(CASE
WHEN NVL (p.pdt_packingweight, 0) > 2
AND 4 >= NVL (p.pdt_packingweight, 0)
THEN pl.picked_qty
ELSE 0
END
) AS weight2
from ......
where ........
group by sh.dc_code, g.bg_code