功能介绍:
将多个表按照维进行对齐关联,这种对其方式是用户不需要关心表之间的连接关系,可以为每张表独立设定汇总维度。
语法描述:
SELECT D.F, T1.f(...), T2.f(...)
ON D AS A
FROM T1 BY ...
UNION T2 BY ...
举例:
SELECT ReturnedPmt.sum(Amount) Pamount,Orders.sum(Amount) Oamount ON YearMonth FROM Orders BY ShipDate#YearMonth UNION ReturnedPmt BY Date#YearMonth |
多表关联,按月份统计订单总额和回款总额 |
SELECT ReturnedPmt.sum(Amount) Pamount,Orders.sum(Amount) Oamount ON year,EMPLOYEE FROM Orders BY ShipDate#year,EmployeeID UNION ReturnedPmt BY Date#year ,SellerID |
多字段关联,按照年份和雇员ID统计订单总额和回款总额 |
知识点:
1)DQL中的UNION相当于SQL中的FULL JOIN连接
2)在多表关联的时候,需要写明字段属于哪张表,并且需要在BY后面写齐字段