|
Sub limonet()
Dim Cn As Object, StrSQL$, StrSQL1$, i%, j%, Arr As Variant, Brr As Variant
Set Cn = CreateObject("Adodb.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Arr = Array("Desc", "Asc"): Brr = Array(5, 10)
StrSQL1 = "Select * From [Sheet1$K1:M5]"
For j = 0 To UBound(Arr)
For i = 0 To UBound(Brr)
StrSQL = "Select Top " & Brr(i) & " 学校,年级,班级,姓名,语文 From [Sheet1$A:G] Order By 语文 " & Arr(j)
StrSQL = "Select 学校,年级,班级,Count(*) As 计数 From (" & StrSQL & ") Group By 学校,年级,班级"
StrSQL1 = "Select a.*,b.计数 From (" & StrSQL1 & ")a Left Join (" & StrSQL & ")b On a.学校=b.学校 And a.年级=b.年级 And a.班级=b.班级"
Next i
Next j
Range("K2").CopyFromRecordset Cn.Execute(StrSQL1)
End Sub |
评分
-
1
查看全部评分
-
|