首页 > 解决方案 > 指定行号起点

问题描述

我在下面有一些示例数据,我想使用 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(需要输出)
美国广播公司 定义 7 500
美国广播公司 定义 0 300 1
美国广播公司 定义 1 200
美国广播公司 定义 0 2 2
美国广播公司 定义 4 30

标签: sqlpostgresql

解决方案


对其他人有 NULL

case when col3 = 0  
   then row_number() over (partition by col1,col2, col3 order by col4 desc) end as row2

推荐阅读