Using Northwind it would be something like this:
Select C.CompanyName, O.ShipCity, Sum(D.Quantity) as Quantity,
Sum(D.Quantity*D.UnitPrice) as Amount
From Customers C Inner Join
Orders O On C.CustomerID = O.CustomerID Inner Join
[Order Details] D on O.OrderID = D.OrderID
Group by C.CompanyName, O.ShipCity
Order by C.CompanyName, O.ShipCity
Thanks a lot for helping me.
"Marc Gravell" <> wrote in message
news:29d78dac-5605-44cf-a8e7-...
> Well, it is hard to test without more info (perhaps something similar
> on "pubs" or "northwind"?) - but perhaps something along the lines of:
>
> var query = from order in db.Orders
> group order by new { Customer = order.Customer,
> SalesPerson = order.SalesPerson }
> into grp
> select new
> {
> Customer = grp.Key.Customer.Name,
> SalesPerson = grp.Key.SalesPerson.Name,
> Quantity = grp.Sum(o => o.Quantity),
> Amount = grp.Sum(o => o.Amount)
> };
>
> foreach (var item in query)
> {
> Console.WriteLine("{0}, {1}, {2}, {3}", item.SalesPerson,
> item.Customer, item.Amount, item.Quantity);
> }
|