可能重複:
SELECT max(x) is returning null; how can I make it return 0?PostgreSQL的轉空到零
當我執行
select max(column) from mytable;
和我的表沒有行,它返回null。我怎樣才能修改這個select語句,使它返回零?
可能重複:
SELECT max(x) is returning null; how can I make it return 0?PostgreSQL的轉空到零
當我執行
select max(column) from mytable;
和我的表沒有行,它返回null。我怎樣才能修改這個select語句,使它返回零?
select coalesce(max(column), 0) from mytable;
嘗試:
SELECT coalesce(max(column), 0) myalias FROM mytable;
做這兩種工作的?
select coalesce(max(foo),0) from bar
coalesce((select max(foo) from bar),0)
工作就像一個魅力!!!! –