我的目标是使用查找与相同的行,并用重复占用的行数替换秩。
如果我有这个结果:
points place
1 300 1
2 267 2
3 245 3
4 245 3
5 240 5
我希望是这样
points place
1 300 1
2 267 2
3 245 3-4
4 245 3-4
5 240 5
那么,如何检查行的位置/点是否具有相同的值,并在其周围构建一个大小写?为了使其更常见:是否有一种方法可以检查2行是否包含相同的值而不给出固定的值?所以类似于column1 = column1而不是column1 =3
发布于 2020-09-23 12:06:20
逻辑是使用窗口函数来确定给定score
的score
值的计数。如果有,则不需要连字符:
select points,
(case when count(*) over (partition by points) = 1
then place
else place || '-' || place || count(*) over (partition by points) - 1
end) as new_place
from t;
这假设place
是一个字符串--但这可能不是真的。所以,你需要一些转换:
select points,
(case when count(*) over (partition by points) = 1
then to_char(place)
else place || '-' || place || count(*) over (partition by points) - 1
end) as new_place
from t;
实际上,不需要min()
位置,因为每一行都是相同的,所以:
https://stackoverflow.com/questions/64027558
复制相似问题