Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created December 9, 2013 16:13
Show Gist options
  • Select an option

  • Save masaru-b-cl/7874894 to your computer and use it in GitHub Desktop.

Select an option

Save masaru-b-cl/7874894 to your computer and use it in GitHub Desktop.
var salesOfCustomers = source.GroupBy(x => x.Customer);
foreach (var salesOfCustomer in salesOfCustomers)
{
var salesOfProducts = salesOfCustomer.GroupBy(x => (x.Product));
foreach (var salesOfProduct in salesOfProducts)
{
foreach (var sales in salesOfProduct)
{
Console.WriteLine(sales);
}
Console.WriteLine("小計 P:{0}, {1}, {2}", salesOfProduct.Key, salesOfProduct.Sum(x => x.Quantity),
salesOfProduct.Sum(x => x.UnitPrice * x.Quantity));
}
Console.WriteLine("大計 C:{0}, {1}, {2}", salesOfCustomer.Key, salesOfCustomer.Sum(x => x.Quantity),
salesOfCustomer.Sum(x => x.UnitPrice * x.Quantity));
}
Console.WriteLine("総計 {0}, {1}", source.Sum(x => x.Quantity), source.Sum(x => x.UnitPrice * x.Quantity));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment