给出了Good
类型的商品goodList
的信息序列和StorePrice
类型的各个商店storePriceList
中商品的价格序列。goodList
序列的每个元素包括 * 产品SKU、类别、原产地 * 字段。storePriceList
序列的每个元素包括 * 产品SKU、商店标题、价格 * 字段。
对于每个原产国,获取提供该国制造的商品的商店数量,以及所有商店中来自该国家的商品的最低价格(国家统计值)。如果在任何商店中均未找到某个国家的产品,则商店数量和最低价格将假定为0。按原产国对列表进行排序。
示例:
goodList: new[]
{
new Good{Id = 1, Country = "Ukraine", Category = "Food"},
new Good{Id = 2, Country = "Ukraine", Category = "Food"},
new Good{Id = 3, Country = "Ukraine", Category = "Food"},
new Good{Id = 4, Country = "Ukraine", Category = "Food"},
new Good{Id = 5, Country = "Germany", Category = "Food"},
new Good{Id = 6, Country = "Germany", Category = "Food"},
new Good{Id = 7, Country = "Germany", Category = "Food"},
new Good{Id = 8, Country = "Germany", Category = "Food"},
new Good{Id = 9, Country = "Greece", Category = "Food"},
new Good{Id = 10, Country = "Greece", Category = "Food"},
new Good{Id = 11, Country = "Greece", Category = "Food"},
new Good{Id = 12, Country = "Italy", Category = "Food"},
new Good{Id = 13, Country = "Italy", Category = "Food"},
new Good{Id = 14, Country = "Italy", Category = "Food"},
new Good{Id = 15, Country = "Slovenia", Category = "Food"}
}
storePriceList: new[]
{
new StorePrice{GoodId = 1, Price = 1.25M, Shop = "shop1"},
new StorePrice{GoodId = 3, Price = 2.25M, Shop = "shop1"},
new StorePrice{GoodId = 5, Price = 4.25M, Shop = "shop1"},
new StorePrice{GoodId = 7, Price = 9.25M, Shop = "shop1"},
new StorePrice{GoodId = 9, Price = 11.25M, Shop = "shop1"},
new StorePrice{GoodId = 11, Price = 12.25M, Shop = "shop1"},
new StorePrice{GoodId = 13, Price = 13.25M, Shop = "shop1"},
new StorePrice{GoodId = 14, Price = 14.25M, Shop = "shop1"},
new StorePrice{GoodId = 5, Price = 11.25M, Shop = "shop2"},
new StorePrice{GoodId = 4, Price = 16.25M, Shop = "shop2"},
new StorePrice{GoodId = 3, Price = 18.25M, Shop = "shop2"},
new StorePrice{GoodId = 2, Price = 11.25M, Shop = "shop2"},
new StorePrice{GoodId = 1, Price = 1.50M, Shop = "shop2"},
new StorePrice{GoodId = 3, Price = 4.25M, Shop = "shop3"},
new StorePrice{GoodId = 7, Price = 3.25M, Shop = "shop3"},
new StorePrice{GoodId = 10, Price = 13.25M, Shop = "shop3"},
new StorePrice{GoodId = 14, Price = 14.25M, Shop = "shop3"},
new StorePrice{GoodId = 3, Price = 11.25M, Shop = "shop4"},
new StorePrice{GoodId = 2, Price = 14.25M, Shop = "shop4"},
new StorePrice{GoodId = 12, Price = 2.25M, Shop = "shop4"},
new StorePrice{GoodId = 6, Price = 5.25M, Shop = "shop4"},
new StorePrice{GoodId = 8, Price = 6.25M, Shop = "shop4"},
new StorePrice{GoodId = 10, Price = 11.25M, Shop = "shop4"},
new StorePrice{GoodId = 4, Price = 15.25M, Shop = "shop5"},
new StorePrice{GoodId = 7, Price = 18.25M, Shop = "shop5"},
new StorePrice{GoodId = 8, Price = 13.25M, Shop = "shop5"},
new StorePrice{GoodId = 12, Price = 14.25M, Shop = "shop5"},
new StorePrice{GoodId = 1, Price = 3.25M, Shop = "shop6"},
new StorePrice{GoodId = 3, Price = 2.25M, Shop = "shop6"},
new StorePrice{GoodId = 1, Price = 1.20M, Shop = "shop7"}
}
预期结果:
expected: new[]
{
new CountryStat{Country = "Germany", MinPrice = 3.25M, StoresNumber = 5},
new CountryStat{Country = "Greece", MinPrice = 11.25M, StoresNumber = 3},
new CountryStat{Country = "Italy", MinPrice = 2.25M, StoresNumber = 4},
new CountryStat{Country = "Slovenia", MinPrice = 0.0M, StoresNumber = 0},
new CountryStat{Country = "Ukraine", MinPrice = 1.20M, StoresNumber = 7},
});
我有一个想法,将storedPriceList
按GoodId
分组,然后选择min Price
,但我不知道下一步该做什么。
3条答案
按热度按时间disbfnqx1#
goodList
通过将Id
与GoodId
匹配来左联接storePriceList
1.按
Country
分组1.请选择:
3.1.获取
Price
的最小值3.2.删除具有非重复空值的
Shop
并执行计数1.按
Country
排序Demo @ .NET Fiddle
l2osamch2#
mlmc2os53#
你可以在一个列表中
Select
个国家,并删除重复的元素(因此是一个所有国家的列表)。从那里你可以很容易地把主列表分成每个国家的货物列表(List<(string Country, List<prices>)>
)