当前位置:  开发笔记 > 数据库 > 正文

如果SQL中的列为空,则返回空白数据

如何解决《如果SQL中的列为空,则返回空白数据》经验,为你挑选了1个好方法。

我运行了以下查询,返回36行数据

SELECT 
    A.OBJECTIVE, SUM(A.T_VALUE)
FROM 
    DB2ADM2.TFINTR10 A
WHERE 
    (A."YEAR" =10)
    AND (A.OBJECTIVE BETWEEN 'WAAAA' AND 'WZZZZ')
GROUP BY 
    A.OBJECTIVE


When I merge with another table and add the Narration field (OB_Narr5) the rows of data are reduced as the Ob_Narr5 does not exist for every Objective, see sql.

    SELECT A.OBJECTIVE, SUM ( A.T_VALUE ), B.OB_NARR5
    FROM DB2ADM2.TFINTR10 A INNER JOIN DB2ADM2.TFINOBJP B ON B.OB_12345 = A.
         OBJECTIVE
    WHERE (A."YEAR" =10)
    AND A.OBJECTIVE BETWEEN 'WAAAA' AND 'WZZZZ'
    GROUP BY A.OBJECTIVE, B.OB_NARR5

The rows returned are now only 4.

How can I return all the rows including the blank fields and / or return just the rows with the blank fields?

感谢回复,Left和Full Outer Join都有效.

How do I replace the  with a blank instead please?

WAAAA   -173597.12  
WABAA   222717.76   GENERAL                         

小智.. 5

使用LEFT JOIN而不是INNER JOIN删除包含空列的左表的条目



1> 小智..:

使用LEFT JOIN而不是INNER JOIN删除包含空列的左表的条目

推荐阅读
和谐啄木鸟
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有