如果没有值,如何使用上一行的值填充Postgres中的列条目?

时间:2017-05-03 04:30:12

标签: postgresql

我有一个包含以下架构的表,其中tstamp是epoch:

Table "public.count_history"
 Column |  Type  | Modifiers 
--------+--------+-----------
 data   | text   | not null
 tstamp | bigint | not null
 count  | bigint | not null
Indexes:
    "count_history_pkey" PRIMARY KEY, btree (data, tstamp)

我有以下自定义功能,可以帮助我将计数分组到#34;桶":

                                                                     List of functions
 Schema |   Name   | Result data type | Argument data types |  Type  | Security | Volatility | Owner | Language |        Source code         | Description 
--------+----------+------------------+---------------------+--------+----------+------------+-------+----------+----------------------------+-------------
 public | ts_round | bigint           | bigint, bigint      | normal | invoker  | volatile   | foo   | sql      |                           +| 
        |          |                  |                     |        |          |            |       |          |   SELECT ($2 * ($1 / $2));+| 
        |          |                  |                     |        |          |            |       |          |                            | 

我有以下查询,可以获取每个"桶的最大计数值"时间,这是24小时:

SELECT data, ts_round(tstamp, 86400) AS tstamp, max(count) AS count FROM count_history GROUP BY 2, 3;

有一段时间可能是空的,在这种情况下,在这段时间内不会返回一行。我怎么能继续使用前一行的count值返回那段时间?

0 个答案:

没有答案