【发布时间】:2021-08-25 20:27:06
【问题描述】:
我正在尝试编写一个查询,在该查询中我根据其他条件更新计数器。例如:
with table 1 as (select *, count from table1)
select box_type,
case when box_type = lag(box_type) over (order by time)
then
count, update table1 set count = count + 1
else
count
end as identifier
这是我正在尝试做的基本要点。我想要一个如下所示的表格:
| box_type | identifier |
|---|---|
| small | 1 |
| small | 1 |
| small | 1 |
| medium | 2 |
| medium | 2 |
| large | 3 |
| large | 3 |
| small | 4 |
我只想在 box_type 每次更改时递增该标识符值
谢谢!
【问题讨论】:
标签: sql postgresql sql-update with-statement case-when