我需要從datacontext的表中選擇日期和平均值,並且需要按年份和月份對它進行分組。 在SQL它看起來像這樣創建日期和平均值的查詢
select Year(data) as years, Month(data) as months, Avg(value) as prices from Prices
group by Year(data),MONTH(data)
order by years, months
我創建了一個LINQ查詢
var query0 = from c in dc.Prices
where Convert.ToDateTime(c.data).CompareTo(left) >= 0
&& Convert.ToDateTime(c.data).CompareTo(right) <= 0
&& c.idsticker.Equals(x)
group c by new { ((DateTime)c.data).Year, ((DateTime)c.data).Month }
into groupMonthAvg
select groupMonthAvg;
但我不知道怎麼弄的結果平均值
它不起作用。添加groupMonthAvg.Key? – lapots 2012-07-09 17:37:22
@ user1432980啊,錯過了 – Candide 2012-07-09 18:08:51