我的桌子像这张桌子:
id no.of sales datetime
1 14 2013-09-10
2 45 2013-09-09
3 18 2013-09-08
4 14 2013-08-12
5 15 2013-08-14
6 18 2013-07-12
在上面第9个月的表格中,这里有3行。在第8个月有2条记录。我需要第9个月和第8个月的所有销售数量的总和,依此类推。可以告诉我如何做到这一点。我的查询:
DateTime frommonth = DateTime.Now.AddMonths(-3);
DateTime tomonth = DateTime.Now;
var result= from pa in cxt.Products
where (pa.datevalue >= frommonth && pa.datevalue < tomonth)
&& pa.productname == productname
orderby pa.datevalue descending
select new { noofsales=pa.No_of_sales ,datetime=pa.datevalue};
通过使用上面的查询,我得到了单独的第9个月记录。我不希望个人销售数量,我需要所有第9个月销售,第8个月销售的总和,等等。请告诉我...
var result = from r in cxt.Products
group r by r.datevalue.Month
into g
select new {Month = g.Key, Sum = g.Sum(p=>p.No_of_sales)};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句