嗨,我很難分組這些數據,因爲它沒有聚合函數。我有兩個表中的以下數據,我想通過PaymentId和display only 1 row of record
加入。分組問題
問:
如何顯示在僅1 ROW GROUPBY CoursePaidForMonthYear最終結果。
我想從Payment.*, TutorCourseCommissions.* and CoursePaidForMonthYear column in same row displaying (September, October, November)
範例中得到的所有數據:
referenceId| TutorId| CoursePaidForMonthYear |
1 | 1019 | September, October, November OR 9,10,11|
我的工作:
var result = from u in db.Users
join p in db.Payments on u.Id equals p.UserId
join tt in db.TutorCourseCommissions on p.Id equals tt.PaymentId into gtt
from tt in gtt.DefaultIfEmpty()
where u.Id == user.Id
GroupBy tt.CoursePaidForMonthYear ??
select new { u, p, tt };
foreach (var r in result)
{
Payment payment = new Payment();
payment.MonthToPay = (r.tt == null) ? null : common.GetMonthName(r.tt.CoursePaidForMonthYear.Month, true);
payment.Amount = r.p.Amount;
output.Add(payment);
}
return output;