I got an inventory table and a stocktransactions table. Items from the inventory can be either sold or freely distributed. I want to write a query that retrieves for each item the total sold, the total distributed for free and the generated revenue for the sale transactions.
something along the lines of :
select i.Id,i.Title,
Sum(case when transactiontype=1 then s.MovedQuantity else 0 end) sold,
Sum(case when transactiontype=1 then s.MovedQuantity*s.UnitPrice else 0 end) Revenue,
Sum(case when transactiontype=0 then s.MovedQuantity else 0 end) distributed
From Inventory i,StockTransactions s
where i.Id=s.ItemId
group by i.Id,i.Title
how can this be done with linq/lambda?
GroupBy,SelectandSumshould do the trick in the right combination.transactiontype?