0
我有一個名爲SQL表瞭解它代表了物理治療師LINQ的次數在過去每週首先會檢查數量的,從28周直到本週
ConsultID ConsultDate Therapist Location
的諮詢誰(治療),我想提出這個數據彙總每星期,開始27周前,直到本週
像:
Location Week-1 Week-2 Week-3 ..... Week-28
Amsterdam 41 38 34 55
Utrecht 65 56 46 46
我怎樣才能做到這一點的LINQ?我有以下幾點:
public ActionResult Therapist(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
DateTime startDate = DateTime.Now.StartOfWeek(DayOfWeek.Monday).AddDays(-168);
DateTime endDate = DateTime.Now.StartOfWeek(DayOfWeek.Sunday);
var TherapistConsult = from row in db.Consults
where ((row.Therapist == id) && (row.ConsultDate > startDate) && (row.ConsultDate < endDate))
group row by row.Location into g
where g.FirstOrDefault() != null
select new
{
Location = g.Key,
// Need a loop here for 28 weeks in the past till this week
// WeekN = g.Count(x => x.Week == N),
};
return View(TherapistConsult.ToList());
}
你嘗試過什麼? – 2014-11-04 09:40:24
肯定的,我有如下所示:var TR =從行諮詢誰在\t \t \t \t \t \t \t其中,((== row.Therapist 44)&&(row.ConsultDate> Convert.ToDateTime(「19-5-2014 00 :00:00 「)&&(row.ConsultDate x.Week == 1) –
2014-11-04 09:42:27
Group通過'ConsultDate',然後從中選擇全部。 – 2014-11-04 09:42:34