【发布时间】:2013-04-21 01:47:54
【问题描述】:
我正在尝试为唯一用户选择 MAX 分数对象。
所以用户应该是不同的,我应该收到用户(订单)的最高分数,我需要为这个最高分数获取其他对象值,如 dataAdded。
$query = $this->createQueryBuilder('s');
$query->select('DISTINCT s.user, s');
$query->where('s.challenge = :challenge')->setParameter('challenge', $challenge);
$query->andWhere('s.date_added BETWEEN :monday AND :sunday')
->setParameter('monday', $startDate->format('Y-m-d'))
->setParameter('sunday', $endDate->format('Y-m-d'));
$query->orderBy('s.score', 'DESC');
//$query->groupBy('s.user');
$query->setMaxResults($limit);
$results = $query->getQuery();
无论我如何尝试,我都无法区分工作。我已经尝试按 MAX(s.score) 分组,但这会将随机对象与最大分数相关联,而不是同一个对象..
有没有人可以解决这个问题? Distinct 似乎不起作用...
生成的查询:
SELECT DISTINCT s.user, s FROM Digital\ApplicationBundle\Entity\ChallengeScore s WHERE s.challenge = :challenge AND (s.date_added BETWEEN :monday AND :sunday) ORDER BY s.score DESC
但是一个错误;(
[Semantical Error] line 0, col 18 near 'user, s FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression
值得一提的是,用户是一种关系。当我在其他文件上尝试此操作时,效果很好...
【问题讨论】:
标签: doctrine-orm doctrine distinct symfony-2.1