sql - 指定行号起点
问题描述
我在下面有一些示例数据,我想使用 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 |
解决方案
对其他人有 NULL
case when col3 = 0
then row_number() over (partition by col1,col2, col3 order by col4 desc) end as row2
推荐阅读
- docker - 在使用 Hyperledger Composer 构建的 Hyperledger Fabric 网络上配置 Kafka 排序服务
- ios - 线程 1:在 TableView Swift 上重新加载数据时,在 AppDelegate 上发出 SIGABRT 信号
- jquery - 是否有在模态表单准备好的事件上触发?我需要在那里设置下拉列表索引
- python - 在 python 3 中使用 win32api/com 模块时,有没有办法解决 unicode 问题?
- python - 是否可以提取嵌入在电子邮件正文中的 SSRS 报告并导出到 csv?
- keras - 根据 Keras TensorBoard 回调,CuDNNLSTM 的零梯度
- c# - 尝试从 c# 中的第四列读取数据 - unity
- php - 将 Wordpress 中的下拉列表或文本字段中的值传递给 functions.php 中的 MySQL 查询
- python - 将 Seaborn 轴转换为对数
- javascript - 关于 replace() 代码,我如何替换辅助“a”字符串?