建议这样做,更直观
Dim sql As String = "Select a.* from {加油记录} a where 5 > (Select count(*) from {加油记录} where 车号 = a.车号 And 日期 > a.日期) order by a.车号,a.日期 desc"
Dim q As new QueryBuilder
q.SelectString = sql
q.TableName = "分析"
q.Build
Dim t As Table = Tables("分析")
Dim g As SubtotalGroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Average
g.GroupOn = "车号"
g.TotalOn = "加油量"
g.Caption = "{0} 平均"
t.SubtotalGroups.Add(g)
t.Subtotal()
MainTable = t