【发布时间】:2020-04-05 14:49:27
【问题描述】:
我有这个示例表:
我需要创建一个排名列,它将根据 is_true=1 对 id 进行排序,这意味着 is_true 从 0 到 1 的每次更改都会使索引增加 1。 类似于以下内容:
我尝试了类似的方法:
select id, customer_id, is_true,
rank() over (partition by customer_id order by (case when is_true=1 then id end)) index_rank
from table
但它不能满足我的需要。
任何帮助将不胜感激。
【问题讨论】:
-
样本数据最好显示为formatted text。请参阅here,了解有关如何创建漂亮表格的一些提示。
标签: sql oracle window-functions