答案 0 :(得分:2)
如果你期望这样的输出
price dte rn
----- ---------- --
65.5 2013-06-01 1
66.3 2014-06-01 1
66.3 2015-12-01 2
67 2012-01-01 1
67 2012-06-01 2
67 2013-01-01 3
67 2014-01-01 4
67 2016-01-01 5
查询应该是
select *
,row_number() over(partition by price order by dte) rn
from price;
OR
SELECT *
,rank() OVER (PARTITION BY price ORDER BY dte) rn
FROM price;
PostgreSQL' Window functions