小编Gli*_*ous的帖子

postgresql中的移动平均线

我的Postgresql 9.1数据库中有以下表格:

select * from ro;
date       |  shop_id | amount 
-----------+----------+--------
2013-02-07 |     1001 |      3
2013-01-31 |     1001 |      2
2013-01-24 |     1001 |      1
2013-01-17 |     1001 |      5
2013-02-10 |     1001 |     10
2013-02-03 |     1001 |      4
2012-12-27 |     1001 |      6
2012-12-20 |     1001 |      8
2012-12-13 |     1001 |      4
2012-12-06 |     1001 |      3
2012-10-29 |     1001 |      3
Run Code Online (Sandbox Code Playgroud)

我试图得到一个移动平均线,比较过去3个星期四的数据而不包括当前的星期四.这是我的查询:

select date, shop_id, amount, extract(dow from date),
avg(amount) OVER (PARTITION BY extract(dow …
Run Code Online (Sandbox Code Playgroud)

postgresql math average moving-average postgresql-9.1

23
推荐指数
2
解决办法
1万
查看次数