方法一:
Dim g As New sqlCrossTableBuilder("统计表1", "加油申请表")
g.ConnectionName = "sqldb"
g.AddTable("加油申请表","牌照号","车辆基本信息表","牌照号")
g.HGroups.AddDef("{车辆基本信息表}.车型")
g.HGroups.AddDef("{加油申请表}.牌照号")
g.VGroups.AddExp("年","Year(iif(Day(日期)> 25,DateAdd('d',6,日期),日期))")
g.VGroups.AddExp("月","Month(iif(Day(日期)> 25,DateAdd('d',6,日期),日期))")
g.Totals.AddDef("数量", "数量")
g.Build()
MainTable = Tables("统计表1")
方法二:
Dim sql As String = "select *,Year(iif(Day(日期)> 25,DateAdd('d',6,日期),日期)) as 年, Month(iif(Day(日期)> 25,DateAdd('d',6,日期),日期)) as 月 f rom {加油申请表} a left join {车辆基本信息表} b on a.牌照号 = b.牌照号"
Dim g As New CrossTableBuilder("统计表1", sql, "sqldb")
g.HGroups.AddDef("车型")
g.HGroups.AddDef("a.牌照号", "牌照号")
g.VGroups.AddDef("年")
g.VGroups.AddDef("月")
g.Totals.AddDef("数量", "数量")
g.Build()
MainTable = Tables("统计表2")