如何参考另一列进行分组和排名
How to group and rank with reference to another column
我在根据主题进行分组或分区和排名方面需要帮助。每个科目都必须有从前到最后的学生。
我在 VB 2010.
中使用下面的代码
Dim TotaledRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
Order By p.Total Descending
For j = 1 To TotaledRecords.Count
TotaledRecords.ToList(j - 1).Position = j
Next
db.SubmitChanges()
我希望它重新启动关于该主题的排名。
见附图:
在这种情况下,您应该先按主题排序,然后再按总数排序。
像这样:
Order By p.Subject, p.Total Descending
如果你想添加一个按主题分组排名的字段,一种方法是这样的:
rank =(From r In db.Assessments _
Order By r.Subject, r.Total _
Where (r.Subject = p.Subject) _
And (r.Total > p.Total) _
Select r).Count + 1 _
... 并且 linq 查询将是这样的:
Dim TotaledRecords = From p In db.Assessments _
Where p.Class = cboclass.Text And p.Stream = cbostream.Text _
Select p, _
rank =(From r In db.Assessments _
Order By r.Subject, r.Total _
Where (r.Subject = p.Subject) _
And (r.Total > p.Total) _
Select r).Count + 1 _
Order By p.Subject, p.Total Descending
我在根据主题进行分组或分区和排名方面需要帮助。每个科目都必须有从前到最后的学生。 我在 VB 2010.
中使用下面的代码Dim TotaledRecords = From p In db.Assessments
Where p.Class = cboclass.Text And p.Stream = cbostream.Text
Select p
Order By p.Total Descending
For j = 1 To TotaledRecords.Count
TotaledRecords.ToList(j - 1).Position = j
Next
db.SubmitChanges()
我希望它重新启动关于该主题的排名。
见附图:
在这种情况下,您应该先按主题排序,然后再按总数排序。 像这样:
Order By p.Subject, p.Total Descending
如果你想添加一个按主题分组排名的字段,一种方法是这样的:
rank =(From r In db.Assessments _
Order By r.Subject, r.Total _
Where (r.Subject = p.Subject) _
And (r.Total > p.Total) _
Select r).Count + 1 _
... 并且 linq 查询将是这样的:
Dim TotaledRecords = From p In db.Assessments _
Where p.Class = cboclass.Text And p.Stream = cbostream.Text _
Select p, _
rank =(From r In db.Assessments _
Order By r.Subject, r.Total _
Where (r.Subject = p.Subject) _
And (r.Total > p.Total) _
Select r).Count + 1 _
Order By p.Subject, p.Total Descending