鉴于下面的表和说明,我试图将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);
我认为您正在尝试创建交叉表格报告。使用INNER JOIN.. USING..
语句。
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
INNER JOIN Tb_Product P USING(P.Supp_ID)
INNER JOIN Tb_Offers O USING(O.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);