【发布时间】:2021-05-06 09:01:53
【问题描述】:
我在下面有一些示例数据,我想使用 row_number 但在 col3 的值为 0 时启动它 我尝试了以下方法,但它不起作用
row_number() over (partition by col1,col2, case when col3 = 0 then 1 end order by col4 desc) as row2
| Col1 | col2 | col3 | col4 | row_number (output wanted) |
|---|---|---|---|---|
| abc | def | 7 | 500 | |
| abc | def | 0 | 300 | 1 |
| abc | def | 1 | 200 | |
| abc | def | 0 | 2 | 2 |
| abc | def | 4 | 30 |
【问题讨论】:
标签: sql postgresql