以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  同一表中有不同期数,不同年级,不同班级的成绩,需要对同一期数,同一年级,同一班级排名,如何设计?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=63125)

--  作者:wlcycxy
--  发布时间:2015/1/14 14:32:00
--  同一表中有不同期数,不同年级,不同班级的成绩,需要对同一期数,同一年级,同一班级排名,如何设计?
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.table


--  作者:Bin
--  发布时间:2015/1/14 14:52:00
--  
参考 http://www.foxtable.com/help/topics/2382.htm
--  作者:wlcycxy
--  发布时间:2015/1/14 14:57:00
--  

我用以下代码对成绩按班级排名,但这种排名不能区别不同年级的同一班级,我需要只针对同一年级同一班级进行排名(比如只针对1年级1班排名,2年级1班另外排名)

e.Form.Controls("Label1").text="请稍等,正在计时..."
Dim timestart,timeend As Date
timestart=Date.now
Dim pm As List(Of String) = CurrentTable.DataTable.GetValues("班级")
Dim pmc As Integer
Dim ColNames() As String = {"语文_成绩","数学_成绩","外语_成绩","科学_成绩","历社_成绩","总分_成绩"}
Dim TotalName As String
CurrentTable.Redraw = False \'刷新表
For Each ColName As string In ColNames
    For i As Integer = 0 To pm.Count -1
        If pm(i) = "" Then
            Continue For
        End If
        Dim drs As List(Of DataRow) = CurrentTable.DataTable.Select("[班级] = " & pm(i), ColName & " DESC")
        pmc = 0
        TotalName = ColName.SubString(0,2) & "_排名"
        For n As Integer = 0 To drs.Count - 1
            pmc = pmc +1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalName ) = drs(n-1)(TotalName )
            Else
                drs(n)(TotalName ) = pmc
            End If
        Next
    Next
Next
Tables("成绩管理").Sort = "总分_成绩 DESC" \'排序,对总分列以降序排序
CurrentTable.Redraw = True \'刷新表
timeend=Date.now
e.Form.Controls("Label1").text="耗时" & (timeend-timestart).TotalSeconds & "秒"
Messagebox.Show("统计完毕!")

                drs(n)(TotalName ) = pmc
            End If
        Next
    Next
Next

[此贴子已经被作者于2015-1-14 15:03:42编辑过]

--  作者:有点甜
--  发布时间:2015/1/14 15:30:00
--  
Dim fls As List(Of String()) = DataTables("成绩管理").GetValues("期数|年级|班级")
For Each fl As String() In fls
    Dim filter As String = "期数 = \'" & fl(0) & "\' and 年级 = \'" & fl(1) & "\' and 班级 = \'" & fl(2) & "\'"
    Dim ColNames() As String = {"语文_成绩","数学_成绩","外语_成绩","科学_成绩","历社_成绩","总分_成绩"}
    For Each ColName As String In ColNames
        Dim TotalName As String = ColName.SubString(0,2) & "_排名"
        Dim drs As List(Of DataRow) = DataTables("成绩管理").Select(filter, colname & " DESC")
        For n As Integer = 0 To drs.Count - 1 \'遍历所有行
            If n > 0 AndAlso drs(n)(ColName) = drs(n-1)(ColName) Then \'如果总分和上一行相同
                drs(n)(TotalName) = drs(n-1)(TotalName ) \'则排名等于上一行
            Else
                drs(n)(TotalName ) = n + 1 \'设置排名
            End If
        Next
    Next
Next

--  作者:wlcycxy
--  发布时间:2015/1/15 9:06:00
--  
我想了一个办法,设置了两个隐藏的表达式列,分别是“年级排名”列和“班级排名”列,“年级排名”列的表达式是:[期数]+[年级],“班级排名”列的表达式是:[期数]+[年级]+[班级],然后利用这两个表达式列进行排名,测试后是可以的