DQLselect所有用户并统计每个用户的预约数量

DQL select all users and count the number of reservations of each

我正在尝试 select 我的所有用户,并为每个用户计算预订和进入的数量。目前我有这个

$qb = $this->createQueryBuilder('user');
return $qb->select('user')
  ->leftJoin('user.reservations', 'reservations')
  ->leftJoin('reservations.marketDate', 'market_date')
  ->addSelect('COUNT(nb_reservations FROM reservations WHERE market_date.date >= CURRENT_DATE())')
  ->orderBy('user.name')
  ->groupBy('user.id')
  ->getQuery()
  ->getResult();

但是我有这个错误

[Semantical Error] line 0, col 59 near 'market_date >=': Error: Class 'market_date' is not defined.

请帮帮我

COUNT 中的语法似乎不正确:COUNT 不应包含整个语句。试试这个:

->addSelect('COUNT(nb_reservations) FROM reservations WHERE market_date.date >= CURRENT_DATE()')

试试这个:

$qb = $this->createQueryBuilder('user');
return $qb->select('user, count(reservations) as count')
  ->leftJoin('user.reservations', 'reservations')
  ->leftJoin('reservations.marketDate', 'market_date')
  ->where('market_date.date >= CURRENT_DATE()')
  ->orderBy('user.name')
  ->groupBy('user.id')
  ->getQuery()
  ->getResult();