也可这样:
Dim sq1,sq2 As String
sq1 = "Select 公司,结算金额 As 发货金额, 0 As 收款金额, 结算金额 As 应收款 F rom{销售结算台账}"
sq2 = "Select 公司,0 As 发货金额, 金额 As 收款金额, -金额 As 应收款 F rom{销售收款台账}"
Dim bd1 As New GroupTableBuilder("统计",sq1 & " Union All " & sq2)
bd1.Groups.AddDef("公司") '根据公司分组
bd1.Totals.AddDef("发货金额") '统计
bd1.Totals.AddDef("收款金额") '统计
bd1.Totals.AddDef("应收款") '统计
bd1.VerticalTotal = True '自动垂直汇总
Dim t1 As Table = Tables("窗口1_Table1")
t1.DataSource =bd1.BuildDataSource()