Hi.
For some statistics reason I need to build a query that looks something
like this.
select u.username, kl.kredit_to
from kredit_log kl left join ups_user u on kl.user_id = u.id,
(select max(createdat) as createdat, user_id from kredit_log group by
user_id) foo
where(foo.user_id = kl.user_id and foo.createdat = kl.createdat)
order by u.username
I want to write it without using NativeQuery. if it possible. So I tried
this
$queryBuilderFrom = $this->getEntityManager()->createQueryBuilder()
->select("max(kl.createdAt) as createdAt, u.id as uid")
->from("NeonusShippingUserBundle:KreditLog", "kl")
->leftJoin("kl.user", "u")
->addGroupBy("u.id");
$queryBuilder = $this->getEntityManager()->createQueryBuilder()
->select("u.username, kl.kreditTo")
->from("NeonusShippingUserBundle:KreditLog", "kl")
->from($queryBuilderFrom, "foo")
->leftJoin("kl.user", "u")
->andWhere("foo.uid = u.id")
->andWhere("foo.createdAt = kl.createdAt")
->orderBy("u.username");
return $queryBuilder->getQuery()->getScalarResult();
It throws me an Exception on the subselect. "Error: Class 'SELECT' is not
defined"
the outputted DQl looks like this:
SELECT u.username, kl.kreditTo FROM NeonusShippingUserBundle:KreditLog kl
LEFT JOIN kl.user u, SELECT max(kl.createdAt) as createdAt, u.id as uid
FROM NeonusShippingUserBundle:KreditLog kl LEFT JOIN kl.user u WHERE kl.type
= :type GROUP BY u.id foo WHERE foo.uid = u.id AND foo.createdAt = kl.createdAt
ORDER BY u.username ASC [image: -]
<http://www.ups.loc/app_dev.php/statistics/credit/balance#>
I want to ask if Doctrine2 has some kind of support of using query as From
source
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.