【问题标题】:DB2 Coalesce not returning expected valueDB2 Coalesce 未返回预期值
【发布时间】:2021-02-26 00:47:54
【问题描述】:

我试图合并两个 last_record 值,但我收到一个空结果,尽管我知道其中一个值不为空。单独查询这些值时,会返回预期的非空值,但通过合并检查时我收到空值。

部分代码:

select rds.*, 
    case when row_num=coalesce(bo.last_record, boa.last_record) 
        then closing - (rolling_debit - debit) else debit end Aged_Debt
    from rolling_debit_sum rds
    inner join balance_overflow bo
        on rds.client_number = bo.client_number
    inner join balance_overflow_aft boa
        on rds.client_number = boa.client_number
    where row_num >= coalesce(bo.last_record, boa.last_record)

我知道last_record 至少在两种情况之一中都不为空,尽管查询对这两种情况都返回空值。有什么想法可能是这里的问题吗?

【问题讨论】:

  • 请清楚什么是NULL,什么不是NULL。您的问题不清楚。

标签: sql db2 coalesce


【解决方案1】:

问题出在联接中。 需要外连接而不是内连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-04
    • 2016-02-13
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多