如何将null(多列)转换为0

时间:2018-03-07 05:31:06

标签: sql postgresql

enter image description here

我想将所有NULL值填充为零 根据我的搜索,我尝试使用coalesce。 我通过PSQL报告错误编写了以下代码:

  

列“coalesce”指定了多次

我想知道为什么以及如何解决它。

select country.name as name, country.electoral_system, 
       coalesce(table4_single.single_party,0), 
       coalesce(table4_two_to_three.two_to_three,0), 
       coalesce(table4_four_to_five.four_to_five,0), 
       coalesce(table4_six_or_more.six_or_more,0)

1 个答案:

答案 0 :(得分:2)

使用coalesce()。这应该有效:

select country.name as name, country.electoral_system, 
       coalesce(table4_single.single_party, 0) as single_party, 
       coalesce(table4_two_to_three.two_to_three, 0) as two_to_three, 
       coalesce(table4_four_to_five.four_to_five, 0) as four_to_five, 
       coalesce(table4_six_or_more.six_or_more, 0) as six_or_more
from table4 join
     country
     on . . .;