数据立方体查找列的最大值
Data Cube Finding Max Values of Columns
我创建了一个名为 Tb_Offers_Cube 的多维数据集,它具有以下特征。问题在于使用 max 函数来查找每个城市提供的最大数量的产品。我一直在为每个城市购买多种产品。
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
--For each supplier city find the product offered in largest quantity?
SELECT [Supplier City], [Product Name], max(DISTINCT [Total Transactions Quantity])
FROM Tb_Offers_Cube
WHERE [Supplier Name] is NULL
AND [Supplier State] is NOT NULL
AND [Supplier City] is NOT NULL
AND [Product Name] is NOT NULL
AND [Product Packaging] is NOT NULL
AND [Product Category] is NULL
AND [Product Line] is NULL
GROUP BY [Supplier City], [Product Name], [Total Transactions Quantity]
ORDER BY [Supplier City], [Total Transactions Quantity] DESC;
您可以获得 max
产品名称 以包含在每个 city
.
的显示中
SELECT [Supplier City]
, [Total Transactions Quantity]
, (SELECT TOP 1 [Product Name] FROM Tb_Offers_Cube WHERE [Total Transactions Quantity] = t.[Total Transactions Quantity]
AND [Supplier City] = t1.[Supplier City]) AS [Product Name]
FROM
(SELECT [Supplier City]
, max(DISTINCT [Total Transactions Quantity]) [Total Transactions Quantity]
FROM Tb_Offers_Cube
WHERE [Supplier Name] is NULL
AND [Supplier State] is NOT NULL
AND [Supplier City] is NOT NULL
AND [Product Name] is NOT NULL
AND [Product Packaging] is NOT NULL
AND [Product Category] is NULL
AND [Product Line] is NULL
GROUP BY [Supplier City]) t
ORDER BY t.[Supplier City], t.[Total Transactions Quantity] DESC;
我创建了一个名为 Tb_Offers_Cube 的多维数据集,它具有以下特征。问题在于使用 max 函数来查找每个城市提供的最大数量的产品。我一直在为每个城市购买多种产品。
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
--For each supplier city find the product offered in largest quantity?
SELECT [Supplier City], [Product Name], max(DISTINCT [Total Transactions Quantity])
FROM Tb_Offers_Cube
WHERE [Supplier Name] is NULL
AND [Supplier State] is NOT NULL
AND [Supplier City] is NOT NULL
AND [Product Name] is NOT NULL
AND [Product Packaging] is NOT NULL
AND [Product Category] is NULL
AND [Product Line] is NULL
GROUP BY [Supplier City], [Product Name], [Total Transactions Quantity]
ORDER BY [Supplier City], [Total Transactions Quantity] DESC;
您可以获得 max
产品名称 以包含在每个 city
.
SELECT [Supplier City]
, [Total Transactions Quantity]
, (SELECT TOP 1 [Product Name] FROM Tb_Offers_Cube WHERE [Total Transactions Quantity] = t.[Total Transactions Quantity]
AND [Supplier City] = t1.[Supplier City]) AS [Product Name]
FROM
(SELECT [Supplier City]
, max(DISTINCT [Total Transactions Quantity]) [Total Transactions Quantity]
FROM Tb_Offers_Cube
WHERE [Supplier Name] is NULL
AND [Supplier State] is NOT NULL
AND [Supplier City] is NOT NULL
AND [Product Name] is NOT NULL
AND [Product Packaging] is NOT NULL
AND [Product Category] is NULL
AND [Product Line] is NULL
GROUP BY [Supplier City]) t
ORDER BY t.[Supplier City], t.[Total Transactions Quantity] DESC;