tags:

views:

31

answers:

3

Hi, I need some help building an Query. I have a table "Orders" with 3 fields (IDorder, IDcostumer and amount) and i'm trying to create an List where i add one row for each costumer with the total of amount.

Can someone help me building this query?

+2  A: 

Try the following:

SELECT IDCustomer, SUM(amount)
FROM Orders
GROUP BY IDCustomer
Ronald Wildenberg
A: 
SELECT sum(amount), IDcostumer FROM Orders GROUP BY IDcostumer
Tom Gullen
A: 

Thanks for the answer. With your query i've tried to joined another table and converted it to LINQ with linqer. The final code was:

from c in contexto.Costumers join s in contexto.Sales on c.IDcostumer equals s.IDCostumer group new {c, s} by new { c.IDcostumer, c.name } into g select new { IDcostumer = (Int32?)g.Key.IDcostumer, g.Key.name, total = (Decimal?)g.Sum(p => p.s.total) }

Unfortunately i haven't understand yet the meaning of group and how it works. I'll read a few articles to try to understand it.

Thanks ;)

Guilherme Cardoso