SQLJoinTableBuilder有一个Union方法,可以组合多个其他SQLJoinTableBuilder的查询结果。
语法:
Union(Builder, All)
Builder:被组合的另一个SQLJoinTableBuilder
All: 可选参数,组合的时候默认是排除重复值的,如果需要组合所有数据,请将此参数设置为True
参与组合的多个SQLJoinTableBuilder,其生成的查询表必须具备相同的结构。
示例
假设你有订单2009、订单2010、订单2011三个表,需要从这三个订单表中找出所有客户为“红阳事业”的订单:
Dim jb1 As New SQLJoinTableBuilder("查询表1","订单2009")
jb1.C
jb1.AddTable("订单","产品ID","产品","产品ID")
jb1.AddTable("订单", "客户ID","客户","客户ID")
jb1.AddCols("产品名称","客户名称","日期", "数量","单价")
jb1.AddExp("金额","数量 * 单价")
jb1.Filter = "客户名称 = '红阳事业'"
Dim jb2 As New SQLJoinTableBuilder("查询表1","订单2010")
jb2.C
jb2.AddTable("订单","产品ID","产品","产品ID")
jb2.AddTable("订单", "客户ID","客户","客户ID")
jb2.AddCols("产品名称","客户名称","日期", "数量","单价")
jb2.AddExp("金额","数量 * 单价")
jb2.Filter = "客户名称 = '红阳事业'"
Dim jb3 As New SQLJoinTableBuilder("查询表1","订单2011")
jb3.C
jb3.AddTable("订单","产品ID","产品","产品ID")
jb3.AddTable("订单", "客户ID","客户","客户ID")
jb3.AddCols("产品名称","客户名称","日期", "数量","单价")
jb3.AddExp("金额","数量 * 单价")
jb3.Filter = "客户名称 = '红阳事业'"
jb1.Union(jb2) '组合jb2
jb1.Union(jb3) '组合jb3
jb1.Build()
MainTable = Tables("查询表1")