4.8 外存维表

SQL

SELECT Customers.CustomerID,CustomerName,Region,City,Amount 
FROM Customers
INNER JOIN Orders ON Orders.CustomerID=Customers.CustomerID
WHERE OrderDate<='2021-12-31' and OrderDate>='2021-01-01'
ORDER BY Amount DESC
LIMIT 1,100

SPL

A
1 >st=date(“2021-01-01”), et=date(“2021-12-31”), start=days@o(st), end=days@o(et)
2 =file(“Orders_Time.ctx”).open().cursor@x(Amount,CustomerID;OrderDate>=start && OrderDate<=end)
3 =A2.groups(;top(100;-Amount)).#1
4 =A3.joinx@q(CustomerID,file(“Customers.ctx”).open():CustomerID,CustomerName,Region,City)

A4 当事实表的数据较少,可以全内存放下,且维表特别大的时候,采用 joinx@q 函数,可快速定位并关联维表,不必对维表全遍历,从而提升效率