PostgreSQL是否有复制功能?
如果与上述条目相同,我的数据对于少数变量的值具有同上符号。 在下面的情况中,如果id值匹配
,是否可以从上一行复制Year的值有无
+------+------+-------+------------+-----+
| Year | Cost | Value | Col1 | id |
+------+------+-------+------------+-----+
| 2014 | 12 | 67 | Natural | 156 |
+------+------+-------+------------+-----+
| " | 23 | 45 | Natural | 156 |
+------+------+-------+------------+-----+
需要
+------+------+-------+------------+-----+
| Year | Cost | Value | Col1 | id |
+------+------+-------+------------+-----+
| 2014 | 12 | 67 | Natural | 156 |
+------+------+-------+------------+-----+
| 2014 | 23 | 45 | Natural | 156 |
+------+------+-------+------------+-----+
答案 0 :(得分:0)
update t
set "Year" = p.y
from (
select *,lag("Year") over (order by id) from t
)
where "Year" is null;
未经过测试(构建小提琴somewhere让人们测试您的数据和代码) - 与事务一起使用