在數據庫(SQL Server)的,比方說,一個列值,如:如何從整數列表中計算排名?
Col1
====
10
5
15
20
5
10
2
這就像整型數據的列表。
排名應該是:
Col1 Rank
==== ====
20 1
15 2
10 3
10 3
5 4
5 4
2 5
我在下面的方式都試過:
1) First sort the list of data in descending order of "Col1" value
2) Find the index of a particular record using FindIndex() method.
3) Then Rank = Index + 1
但是,如果數據是唯一的它只會工作。當索引返回0, 1, 2, 3, 4, 5, 6
時,如果同一個「Col1」值出現在多行中,它將失敗。
如何使用C#LINQ來計算列表包含不明顯的數據(大多數情況下!)的等級?
什麼,如果第一,然後採取不同的值做了上面的場景... –