输入:

输出:

我想要如下图所示的输出。
在输出图像中,“落后”中的4被评估为tot_cnt-tot,而“落后”中的后续数字,例如:2被评估为滞后(落后)-tot&只要“排名”保持不变,即使“落后”也应该保持不变。
有没有人能帮我在teradata中实现这个?
发布于 2018-07-26 21:04:24
您似乎想要:
select *, (select count(*)
from table t1
where t1.rank > t.rank
) as behind
from table t;发布于 2018-07-26 21:45:33
我将总结数据并执行以下操作:
select id, max(tot_cnt), max(tot),
(max(tot_cnt) -
sum(max(tot)) over (order by id rows between unbounded preceding and current row)
) as diff
from t
group by id;这为每个id提供了一行,这对我来说更有意义。如果您想要原始数据行(无论如何都是重复的),您可以将其join回表中。
https://stackoverflow.com/questions/51539271
复制相似问题