DB2数据库SQL将不同行做合计
案例:
将’GL’和’RZ’做合计,其他的不动。
SELECT SALE_TYPE,ROUND(CAST(SUM(aatp_weight) AS DOUBLE),2) AS aatp_weight
FROM(
SELECT
CASE WHEN SALE_TYPE = 'GL' THEN 'RZ' ELSE SALE_TYPE END AS SALE_TYPE,
DEMAND_NUM / 10000 AS aatp_weight
FROM TABLEName
WHERE ORDER_MONTH = '202308'
)
GROUP BY SALE_TYPE