如何获得最大日期的加入记录?

时间:2019-03-29 07:15:13

标签: c# sql linq

如何在LINQ中做到这一点?

 public retryServerCheck(): Observable<boolean | HttpError> {
  return this._httpClient.get<boolean>(this.baseUrl + 'ServerCheck')
    .pipe(
      retryWhen(errors => errors.pipe(delay(500))),
      catchError(err => {
        return this._helperService.handelHttpError(err);
      })
    );
}

数据库图在这里->

dbdiagram

例如加入就是这样,但我无法获得DepartureDateRange和ReturnDateRange的最大值

select  MAX(d.DepartureDateRange),MAX(d.ReturnDateRange)   
from Tour t join
TourCategory tc on t.ID = tc.TourID
join TourDates td on t.ID = td.TourID
join Dates d on d.ID = td.DatesID
where tc.CategoryID = 3 and t.ID = 12 

谢谢。

2 个答案:

答案 0 :(得分:2)

在这里(日期按游览分组):

var query2 = 
    from t in db.Tour
    join tc in db.TourCategory on t.ID equals tc.TourID
    where tc.CategoryID == 3
    // join dates aggregates grouped by tour id
    join tdates in
        from td in db.TourDates 
        join d in db.Dates on td.DatesID equals d.ID
        group d by td.TourID into grp
        select new 
        { 
            tourID = grp.Key, 
            departure = grp.Max(g => g.DepartureDateRange), 
            rtrn = grp.Max(g => g.ReturnDateRange)
        }
    on t.ID equals tdates.tourID
    select new IndexTour
    {
        ID = t.ID,
        TourName = t.TourName,
        DepartureDateRange = tdates.departure,
        ReturnDateRange = tdates.rtrn,
        Description = t.SmallDesc,
        Price = t.Price,
        CoverPhotoUrl = t.CoverPhotoUrl,
        TourProgram = t.TourDesc
    };

答案 1 :(得分:0)

认为这就是你想要的吗?

    function filteredArray(arr, elem) {   
let newArr = [];   
for (let i = 0; i < arr.length; i++) {  var check = false;
    for (let j = 0; j < arr[i].length; j++) {
      if (arr[i][j] == elem) {
       check = true;
      }
    }
       } // change code above this line
    return newArr; 
}