目前正试图找到最大值,对于芝加哥唯一的计算机应该出现,因为它的数量是1010它是最大的数量
以下是对上述多维数据集执行的查询。我只想找到每个城市产品名称的最大数量。
SELECT [Supplier City], [Product Name], [Total Transactions Quantity]
FROM Tb_Final_Cube
WHERE "Supplier Name" IS NULL
AND "Supplier City" IS NOT NULL
AND "Supplier State" IS NOT NULL
AND "Product Packaging" IS NOT NULL
AND "Product Name" IS NOT NULL
AND "Product Category" IS NULL
AND "Product Line" IS NULL
答案 0 :(得分:1)
使用窗口功能:
SELECT tfb.*
FROM (SELECT [Supplier City], [Product Name], [Total Transactions Quantity],
ROW_NUMBER() OVER (PARTITION BY [Product Name] ORDER BY [Total Transactions Quantity] DESC) as seqnum
FROM Tb_Final_Cube
WHERE "Supplier Name" IS NULL AND
"Supplier City" IS NOT NULL AND
"Supplier State" IS NOT NULL AND
"Product Packaging" IS NOT NULL AND
"Product Name" IS NOT NULL AND
"Product Category" IS NULL AND
"Product Line" IS NULL
) tfb
WHERE seqnum = 1;