【问题标题】:Postgresql turn null into zero [duplicate]Postgresql将null变为零[重复]
【发布时间】:2011-09-17 04:46:43
【问题描述】:

可能重复:
SELECT max(x) is returning null; how can I make it return 0?

当我执行时

select max(column) from mytable;

我的表没有行,它返回 null。如何修改此 select 语句使其返回零?

【问题讨论】:

    标签: sql postgresql null max


    【解决方案1】:
    select coalesce(max(column), 0) from mytable; 
    

    【讨论】:

    • 工作就像一个魅力!!!!
    【解决方案2】:

    试试:

    SELECT coalesce(max(column), 0) myalias FROM mytable;
    

    【讨论】:

      【解决方案3】:

      这些都行吗?

      • select coalesce(max(foo),0) from bar
        
      • coalesce((select max(foo) from bar),0)
        

      【讨论】:

        猜你喜欢
        • 2016-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多