Kaveh Yzd Kaveh Yzd - 1 year ago 191
MySQL Question

query and subquery in symfony

i use query and sub query in symfony query builder, but when use my result is error

my code is :

$subQb = $em->createQueryBuilder();

$subquery = $subQb->select('COUNT(v.id)')
->from('AdminBundle:Visitsite', 'v')
->where('v.site = s.id')
->Andwhere('v.createdate > :date')
->setParameter('date', $date->format('Y-m-d'))

$subQb2 = $em->createQueryBuilder();
$subquery2 = $subQb2->select('quantity')
->from('AdminBundle:Limitviewday', 'l')
->where($subQb2->expr()->eq('s.limitviewday', 'l.id'))

$qb = $em->createQueryBuilder();
$query = $qb->select('s')
->from('AdminBundle:Sites', 's')
->where('s.quantity > 1')
->Andwhere('s.status = 1')
->Andwhere($qb->expr()->lte("($subquery)", "($subquery2)"));

$settlements = $query->getQuery()->getResult();

and my result is

[Semantical Error] line 0, col 183 near 'quantity FROM': Error: 'quantity' is not defined.

please help me.

Answer Source

I think that error come from:

$subquery2 = $subQb2->select('quantity') // Expected '<alias>' or '<alias>.<property>'


$subquery2 = $subQb2->select('l.quantity')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download