Sum of the most recent non-null columns (window function with “ignore nulls”)

后端 未结 2 946
独厮守ぢ
独厮守ぢ 2021-01-22 19:53

I am using PostgreSQL 9.1.9.

In the project I am working on, some most recent records have null columns because that information was not available when that row was crea

相关标签:
2条回答
  • 2021-01-22 20:32

    You can use this custom aggregate as a postgres variant of FIRST_VALUE(expression INGORE NULLS). Or build your own aggregate with desired behavior.

    0 讨论(0)
  • 2021-01-22 20:45

    Is this what you are trying to describe?

    SELECT sum(col1), sum(col2), sum(col3) FROM table2 WHERE col1 IS NOT NULL
    

    (although I omitted the join on table1; that is an exercise for the reader)

    0 讨论(0)
提交回复
热议问题