内部联接以获取typeorm中的平均值

时间:2020-10-18 22:04:44

标签: nestjs typeorm

我是Typeorm的新手,我写了一个查询,该查询将内部联接并选择多个表,如下所示:

  async findAllTripsWithSpecificStatusForUser(id: string, pageIndex: number, pageSize: number, sort: 'ASC' | 'DESC'): Promise<[Trip[], number]>{    
let sortBy:'ASC' | 'DESC' = 'DESC';
if (sort) {
  sortBy = sort;
}

return await this.tripRepository.createQueryBuilder("trip")
.innerJoinAndSelect("trip.matches", "matches")
.where("trip.state = :state", {
  state: 1
})
.andWhere("trip.state = :state", {
  state: 3
})
.innerJoin("trip.clientAccount", "clientAccount")
.innerJoin("clientAccount.user", "user")
.innerJoin("user.reputation", "reputation")
.innerJoinAndSelect("matches.truck", "truck")
.innerJoinAndSelect("truck.transporterAccount", "transporterAccount")
.where("transporterAccount.id = :userUuid", {
    userUuid: id
})
.skip(pageIndex * pageSize)
.take(pageSize)
.getManyAndCount();
  }

每个用户在信誉表中都有许多评级值。我想选择这些值的平均值并返回它们。

如何实现呢?我想我需要使用某种子查询吗?

0 个答案:

没有答案