【发布时间】:2019-12-13 00:22:57
【问题描述】:
鉴于下面的表格和描述,我尝试将 SQL 与 GROUP BY、CUBE 和 ROLLUP 结合使用来创建多维数据集。我的查询有问题,因为基数应该返回约 1440 行,但我的多维数据集的基数只返回 59...
Tb_Supplier(Supp_ID, Name, City, State)
Tb_Consumer(Con_ID, Name, City, State)
Tb_Product(Prod_ID, Name, Product_Category, Product_Line, Product_Packaging)
Tb_Offers(Supp_ID, Prod_ID, Quantity, Price)
Tb_Requests(Con_ID, Prod_ID, Quantity, Price)
Tb_Transactions(Tran_ID, Supp_ID, Con_ID, Prod_ID, Quantity, Price)
The dimensions of the cube are: Tb_Supplier and Tb_Product.
Measure groups table is: Tb_Offers.
Measure aggregates: SUM(Quantity), SUM(Quantity*Price),
MAX(Price) , MIN(Price).
Dimension hierarchies:
Tb_Supplier: State > City > Name
Tb_Product: Product_Packaging > Name
Product_Category > Product_Line > Name
SELECT DISTINCT S.Name "Supplier Name", S.State "Supplier State", S.City "Supplier City",
P.Name "Product Name", P.Product_Packaging "Product Packaging",
P.Product_Category "Product Category", P.Product_Line "Product Line",
SUM(Quantity) "Total Transactions Quantity", SUM(Quantity*Price) "Total Transaction Price",
MAX(Price) "Maximum Price", MIN(Price) "Minimum Price"
INTO Tb_Offers_Cube
FROM Tb_Supplier S, Tb_Product P, Tb_Offers O
WHERE S.Supp_ID = O.Supp_ID
AND O.Prod_ID = P.Prod_ID
GROUP BY CUBE((S.State, S.City, S.Name),
(P.Product_Packaging, P.Name),
(P.Product_Category, P.Product_Line, P.Name)),
ROLLUP(S.State, S.City, S.Name),
ROLLUP(P.Product_Packaging, P.Name),
ROLLUP(P.Product_Category, p.Product_Line, P.Name);
【问题讨论】:
-
你试过用左连接吗?
-
@ϻᴇᴛᴀʟ 我没有。那么我会在维度表上创建连接吗?我对立方体还很陌生。