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?
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?
Try the following:
SELECT IDCustomer, SUM(amount)
FROM Orders
GROUP BY IDCustomer
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 ;)