将Postgresql中的空值转换为零

68
3个回答

143
select coalesce(max(column), 0) from mytable; 

1
即使过了11年,也能拯救生命,感谢你。 - SAIF AHMED ANIK

17

尝试:

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

9
这两个方案都可行吗?
  • select coalesce(max(foo),0) from bar
    
  • coalesce((select max(foo) from bar),0)
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接