|
[ 本帖最后由 魂断蓝桥 于 2019-5-14 16:04 编辑 ]\n\nvbRC5BaseDlls.zip (~ 2.7MB, current version: 5.0.68, last update: 2019-05-12 ... latest SQLite-version: 3.28)
终于更新到了3.28 可以支持窗口函数了,简单的测试了一下,我的电脑伪序号,班级排名,年级排名 数据量为6000多条的时候,
用时不超过0.50秒。
还有更多的,没太看懂文档。
SQLite supports the following 11 built-in window functions:row_number()The number of the row within the current partition. Rows are numbered starting from 1 in the order defined by the ORDER BY clause in the window definition, or in arbitrary order otherwise.rank()The row_number() of the first peer in each group - the rank of the current row with gaps. If there is no ORDER BY clause, then all rows are considered peers and this function always returns 1.dense_rank()
地址是: [url]https://www.sqlite.org/windowfunctions.html#wchaining[/url]
Option Explicit
Sub A()
Dim CNN As New cConnection
Dim RS As New cRecordset
Dim ARR, I%, J%, SQL$, tim
tim = Timer
Application.ScreenUpdating = False
ARR = Sheet2.[A1].CurrentRegion
CNN.CreateNewDB
SQL = "CREATE TABLE T1 (ID INTEGER PRIMARY KEY,班级 TEXT,成绩 DOUBLE)"
CNN.Execute SQL
CNN.BeginTrans
For I = 2 To UBound(ARR)
SQL = "INSERT INTO T1 (班级,成绩) VALUES('" & ARR(I, 1) & "'," & ARR(I, 2) & ")"
CNN.Execute SQL
Next
CNN.CommitTrans
Sheet2.Activate
[D:Z].Clear
SQL = "SELECT 班级,成绩," _
& "row_number() OVER (ORDER BY 成绩 DESC) AS 伪序号" _
& ",RANK() OVER (ORDER BY 成绩 DESC) AS 年级排名" _
& ",RANK () OVER (PARTITION BY 班级 ORDER BY 成绩 DESC) AS 班级排名 FROM T1 ORDER BY 1,2 DESC"
RS.OpenRecordset SQL, CNN
For I = 0 To RS.Fields.Count - 1
Cells(1, I + 4) = RS.Fields(I).Name
Next
Range("D2").CopyFromRecordset RS.GetADORsFromContent
Set RS = Nothing
Set CNN = Nothing
ActiveSheet.ListObjects.Add(xlSrcRange, Range("D1").CurrentRegion, , xlYes).Name = "表2"
ActiveSheet.ListObjects("表2").TableStyle = "TableStyleMedium22"
Range("D1").CurrentRegion.AutoFilter
Range("D:H").Font.Name = "微软雅黑"
Range("D:H").Font.Size = 11
Application.ScreenUpdating = True
MsgBox Format(Timer - tim, "0.00")
End Sub
|
评分
-
4
查看全部评分
-
|