为每个消费者找到购买的最便宜的产品

For each consumer find the cheapest product that was purchased

我正在尝试从多维数据集中获取每位消费者购买的最便宜产品的列表。我尝试了以下多维数据集查询:

SELECT "Consumer Name","Product Name",MIN([Total Price]) AS "Total Purchase Price"
FROM Transaction_Cube 
WHERE "Consumer Name" IS NOT NULL
    AND "Consumer City" IS NOT NULL
    AND "Consumer State" IS NOT NULL       
    AND "Product Name" IS NOT NULL 
    AND "Product Category" IS NOT NULL
    AND "Product Line" IS NOT NULL
    AND "Product Packaging" IS NOT NULL
GROUP BY "Consumer Name","Product Name"

但这给了我以下结果:

我在其中获得每个 consumer/product 组合的最低购买价格。但我想要实现的是这样的:

我只为每个消费者提供了购买的最便宜的产品。任何关于如何更正此查询的想法或建议将不胜感激!

您不需要 GROUP BY "Consumer Name","Product Name"
检查这个:

SELECT t.[Consumer Name], t.[Product Name], t.[Total Price] AS "Total Purchase Price"
FROM Tb_Transactions_Cube_FE t
WHERE 
t.[Total Price] = (SELECT MIN([Total Price]) FROM Tb_Transactions_Cube_FE WHERE [Consumer Name] = t.[Consumer Name])
ORDER BY t.[Consumer Name]