t-sql:每次出现标志时增加的密集等级
t-sql: dense rank that is increased at every occurence of a flag
我有一个 table 有 Parent 行和 Children 行。
table 由递增序列、表示它是 child 还是 parent 的行和代码组成。我需要创建仅在每次出现 IsParent 列 (values:0,1).
时增加的排名(增加的数字)
这是我的table:original table
这是理想的结果table:result table
DDL 和示例数据会很棒,但是,看起来您想使用 Window 函数。这未使用您的数据进行测试,但这应该会为您提供预期的输出。
SUM(IsParent) OVER (ORDER BY [Row Number]
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
我有一个 table 有 Parent 行和 Children 行。 table 由递增序列、表示它是 child 还是 parent 的行和代码组成。我需要创建仅在每次出现 IsParent 列 (values:0,1).
时增加的排名(增加的数字)这是我的table:original table
这是理想的结果table:result table
DDL 和示例数据会很棒,但是,看起来您想使用 Window 函数。这未使用您的数据进行测试,但这应该会为您提供预期的输出。
SUM(IsParent) OVER (ORDER BY [Row Number]
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)