求和 NULL 或将 NULL 转换为 0 求和 sql db2.iseries

sum NULL or converting NULL to 0 to sum sql db2.iseries

我是 SQL 的新手,目前正在尝试查询 DB2.iSeries 数据库,但我被卡住了。

这是我的代码:

SELECT IPROD, IDESC, IMRP, NONAV
FROM

(SELECT IPROD, IDESC, IMRP FROM IIM WHERE IBUYC IN (<pln.value>) AND IMRP = 'N') AS IM

INNER JOIN
(SELECT I01PROD FROM INV01P
WHERE I01SUPS = '0'
AND I01SUPP = '0')
AS L1 ON IM.IPROD = L1.I01PROD

LEFT OUTER JOIN
(SELECT WPROD, SUM(WOPB-WISS+WADJ+WRCT) AS NONAV FROM IWI
WHERE LEFT(WWHS,1) = '9'
GROUP BY WPROD) AS L2 ON IM.IPROD = L2.WPROD

GROUP BY IPROD, IDESC, IMRP, NONAV
HAVING SUM(NONAV) = 0

ORDER BY IPROD
FETCH FIRST 10000 ROWS ONLY

这是我的代码,在查询时工作正常:HAVING SUM(NONAV) = 0,但我遇到的问题是有些产品具有 NULL 值,我也需要提取这些产品。

我在查询的不同点尝试了 IFNULLCASE WHEN,但都失败了。

我知道如何使用 0 进行字段输出视图,但是当涉及到求和时,它无法提取这些产品。

字段求和后,有人可以帮我提取 NULL 和 0 值吗?

谢谢

SELECT IPROD, IDESC, IMRP, NONAV
FROM

(SELECT IPROD, IDESC, IMRP FROM IIM WHERE IBUYC IN (<pln.value>) AND IMRP = 'N') AS IM

INNER JOIN
(SELECT I01PROD FROM INV01P
WHERE I01SUPS = '0'
AND I01SUPP = '0')
AS L1 ON IM.IPROD = L1.I01PROD

LEFT OUTER JOIN
(SELECT WPROD, SUM(WOPB-WISS+WADJ+WRCT) AS NONAV FROM IWI
WHERE LEFT(WWHS,1) = '9'
GROUP BY WPROD) AS L2 ON IM.IPROD = L2.WPROD

GROUP BY IPROD, IDESC, IMRP, NONAV
HAVING SUM(COALESCE(NONAV,0)) = 0

ORDER BY IPROD
FETCH FIRST 10000 ROWS ONLY