用于查看值出现超过 1 SQL 服务器的排名函数

Rank function to see value appearing more than 1 SQL SERVER

我需要一些建议和帮助,因为我正在尝试使用适当的排名函数在 SQL SERVER 中进行实验。

基本上,我想做的是统计合同协议在数据中重复了多少次。在Excel中,我使用了Count(A:A;A2)

Cust_Nr    Contract Agreement Nr
5639232    19243062
10072067   3316516
10072067   3316516
5639232    19243062
20095770   49940680
10072067   3316516

我的问题是,有没有一种方法可以使用 Rank of Rank Dense 函数计算 contract agreement Nr 出现的次数不止一次?例如,contract agreement nr:3316516 出现了两次。我想要一个显示此内容的另一列:

Cust_Nr    Contract Agreement Nr  Duplicate
5639232    19243062
10072067   3316516                3
10072067   3316516                3
5639232    19243062
20095770   49940680
10072067   3316516                3

所以contract agreement nr 3316516在数据中一共出现了3次

我该怎么做?

就用这个,不需要排名:

select *, count(*) over (partition by [Contract Agreement Nr]) as RowsPerContractNumber
from MyTable

编辑:如果您希望非重复行为空,请使用:

select *
, case count(*) over (partition by [Contract Agreement Nr]) 
    when 1 then ''
    else cast(count(*) over (partition by [Contract Agreement Nr]) as varchar)
end
as RowsPerContractNumber
from MyTable