Foxtable(狐表)用户栏目专家坐堂 → [求助]如何取众数


  共有1824人关注过本帖树形打印复制链接

主题:[求助]如何取众数

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/3 16:43:00 [显示全部帖子]

 表达式无法取众数的函数,要用代码,参考

 

Dim dic As new Dictionary(Of String, Integer)
Dim count As Integer = 0
For Each dr As DataRow In DataTables("表A").Select("")
    Dim v As String = dr("第三列")
    If dic.ContainsKey(v) = False Then
        dic.Add(v, 1)
    Else
        dic(v) += 1
    End If
    If dic(v) > count Then
        count = dic(v)
    End If
Next
For Each key As String In dic.keys
    If dic(key) = count Then
        msgbox(key & " " & dic(key))
    End If
next


 回到顶部