asp统计的问题
我有一个表格,里面有班级,性别,姓名,现在我想将人数按班级和男女的情况用表格的形式统计出来,形式就是这样的。
班级 性别 人数
一年级一班 女 10
男 10
一年级二班 女 15
男 10
一年级二班 女 15
男 10
一年级二班 女 15
男 10
一年级二班 女 15
男 10
一年级三班 女 20
男 25
....等类似的
代码如下。
Dim strSQL,objRs,sB,sF,i,cC,cN,cV
sB = RQuery("bj")
cC = 0
cN = 0
cV = 0
strSQL = "SELECT 班级,性别,Count(*) As 人数 FROM sTable Where 当前状态 Not Like '%1%'"
If sB&""<>"" Then strSQL = strSQL & " And 年级='"&sB&"'"
strSQL = strSQL & " group by 班级,性别"
Set objRs = oConn.Execute(strSQL)
Set sF = objRs.Fields
Call PHead("人数统计")
If Not objRs.Eof Then
Print "<table align='center' width='80%' cellspacing='1' cellpadding='4' class='table1'>"
Print "<thead style='display:table-header-group;'>"
Print "<tr><td class='thetitle' style='text-align:center;background:#fff' colspan='"&sF.Count+1&"'>"
Print ""©Right&" 各班级人数统计"
Print "</td></tr>"
Print "<tr class='thead'>"
For i = 0 To sF.Count-1
Print "<td>"&sF(i).Name&"</td>"
Next
Print "</tr>"
Print "</thead>"
Print "<tbody>"
Do While Not objRs.Eof
If cC Mod 40 = 0 And cC>0 Then
Print "<tr style='page-break-before:always' class='tbody' onmouseout=""this.style.background='#ffffff'"" onmouseover=""this.style.background='#f5f5f5'"">"
Else
Print "<tr class='tbody' onmouseout=""this.style.background='#ffffff'"" onmouseover=""this.style.background='#f5f5f5'"">"
End If
For i = 0 To sF.Count-1
If i = 0 Then
If cC Mod 2 = 0 Then
Print"<td rowspan='2' class='thead'>"&sF(i).Value&"</td>"
'else
' Print "<td>"&sF(i).Value&"</td>"
end if
Else
Print "<td>"&sF(i).Value&"</td>"
End If
Next
Print "</tr>"
cC = cC + 1
If Trim(objRs("性别"))="女" Then
cV = cV + objRs("人数")
Else
cN = objRs("人数")
End If
objRs.MoveNext
If objRs.Eof Then Exit Do
Loop
Print "</tbody>"
Print "<tfoot style='display:table-footer-group;'>"
Print "<tr><td class='tbody' colspan='"&sF.Count+1&"'>"
If sB&""<>"" Then
Print sB & "级"
Else
Print "全校"
End If
Print " 共有 "&cN+cV&" 人,其中男生 "&cN&" 人,女生 "&cV&" 人。</td></tr>"
Print "</tfoot>"
Print "</table>"
可是这个代码有个问题,就是如果这个班上没有男生的话,那么就显示的班级和性别,人数都错位了,所以,这样就变成了这样的
班级 性别 人数
一年级一班 女 10
女 15
一年级二班 男 10
女 25
一年级三班 男 20