以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  统计效率问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=96871)

--  作者:刘林
--  发布时间:2017/3/1 14:14:00
--  统计效率问题
afterload:
Dim school As String = User.Group
If school IsNot Nothing
e.Form.Controls("label1").text = school & "学生基本信息统计"
Else
e.Form.Controls("label1").text = "学生基本信息统计"
End If
Dim lbl As WinForm.Label = e.Form.Controls("Label1")
If e.Form.width > lbl.Width
    lbl.Left = (e.Form.width - lbl.Width ) / 2
   End If
DataTables("学生统计").loadfilter = "单位全称 = \'"& school & "\'"
DataTables("学生统计").load
Tables("学生人数统计_table2").sort = "班级"
Tables("学生人数统计_table2").Cols("在读人数").GrandTotal = True \'指定要合计的列
Tables("学生人数统计_table2").Cols("男").GrandTotal = True
Tables("学生人数统计_table2").Cols("女").GrandTotal = True
Tables("学生人数统计_table2").Cols("户口性质_农业户口").GrandTotal = True
Tables("学生人数统计_table2").Cols("户口性质_非农业户口").GrandTotal = True
Tables("学生人数统计_table2").Cols("无身份证").GrandTotal = True
Tables("学生人数统计_table2").Cols("无学籍号").GrandTotal = True
Tables("学生人数统计_table2").Cols("残疾").GrandTotal = True
Tables("学生人数统计_table2").Cols("走读").GrandTotal = True
Tables("学生人数统计_table2").Cols("住读").GrandTotal = True
Tables("学生人数统计_table2").GrandTotal = True \'显示合计模式

刷新按键:
Dim school As String = User.Group
Tables("学生统计").sort = "班级"
Dim Vals As List(of String())
Dim drf As DataRow
Vals = DataTables("学生信息").sqlGetValues("学校名称|班级","学校名称 = \'" & school & "\'")
For i As Integer = 0 To Vals.Count - 1
drf = DataTables("学生统计").SQLFind("单位全称 = \'" & vals(i)(0) & "\' and 班级 = \'" & vals(i)(1) &"\'" )
 If drf Is Nothing
 Dim dr As DataRow = DataTables("学生统计").AddNew()
    dr("单位全称") = Vals(i)(0)
    dr("班级") = Vals(i)(1)
DataTables("学生统计").save()
End If
Next
DataTables("学生统计").DataCols("单位全称").RaiseDataColChanged()
DataTables("学生统计").save()

老师,上面两个代码是用于窗口中统计学生信息表中的数据,但效率太低了,请示帮用sql语句实现上面统计怎样写

--  作者:y2287958
--  发布时间:2017/3/1 14:33:00
--  
上例子
--  作者:有点色
--  发布时间:2017/3/1 15:08:00
--  

先检查是sqlfind导致的,还是重置列导致的。

 

尽量不要在循环中使用sqlfind。

 

如果是重置列,拷贝datacolchanged事件的代码出来修改使用。


--  作者:刘林
--  发布时间:2017/3/1 19:56:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目5.foxdb

请老师帮改下,上次有位老师帮把一个效率很低的用sql语句改后很快,但看不懂,请看这个窗口效率如何改?谢谢!!
--  作者:有点色
--  发布时间:2017/3/1 20:09:00
--  

参考代码

 

select 学校名称,班级, (select count(*) from {学生信息} as b where a.学校名称=b.学校名称 and a.班级=b.班级 and 性别=\'男\') as 男,(select count(*) from {学生信息} as b where a.学校名称=b.学校名称 and a.班级=b.班级 and 性别=\'女\') as 女 from (select 学校名称,班级 from {学生信息} group by 学校名称,班级) as a where 学校名称 = \'内江市东兴区石子镇中心学校\'


--  作者:刘林
--  发布时间:2017/3/1 20:54:00
--  
真的是飞快,但老师确实懂不起,麻烦你帮我将项目的想法写出来一下,以后好慢慢研究学习
--  作者:有点色
--  发布时间:2017/3/1 21:47:00
--  

拷贝修改红色代码即可。

 

Dim school As String = User.Group
Dim t As Table = e.Form.controls("Table2").Table
t.Fill("select 学校名称,班级, (select count(*) from {学生信息} as b where a.学校名称=b.学校名称 and a.班级=b.班级 and 性别=\'男\') as 男,(select count(*) from {学生信息} as b where a.学校名称=b.学校名称 and a.班级=b.班级 and 性别=\'女\') as 女 from (select 学校名称,班级 from {学生信息} group by 学校名称,班级) as a where 学校名称 = \'" & school & "\'", "sy", True)
t.sort = "班级"
For Each c As Col In t.Cols
    If c.IsNumeric Then
        c.GrandTotal = True
    End If
Next
t.GrandTotal = True \'显示合计模式


--  作者:刘林
--  发布时间:2017/3/1 22:19:00
--  
“sy"是什么?
--  作者:有点色
--  发布时间:2017/3/1 22:46:00
--  
以下是引用刘林在2017/3/1 22:19:00的发言:
“sy"是什么?

 

sy,是你的数据源名

 

http://www.foxtable.com/webhelp/scr/2912.htm

 


--  作者:刘林
--  发布时间:2017/3/2 8:29:00
--  
请问加个各班人数统计怎么加,人数要统计状态的左边两个字符为在读