2016-11-10 75 views
0

我需要通过像的多个字段中的教义来筛选下列:学说滤波

SELECT company , state 
FROM employees 
WHERE 
(company, state) <> ('xxxxx', 'xxxx') 
AND 
(company, state) <> ('xxxx', 'xxxx') 
GROUP BY company, state 

我尝试以下方法:

$qb->andWhere($qb->expr()->andX($qb->expr()->neq('b.company',"'".$i['description']."'"), $qb->expr()->neq('b.state', "'".$i['state']."'"))); 

但结果是不期望的:

(company <> 'xxxxx' AND state <> 'xxxx') AND (company <> 'xxxxx' AND state <> 'xxxxx') 

我该如何做第一个通过学说? 问候!

回答

0

上面的查询可以作为两个列表的OR来工作,这会让事情变得更简单。

E.g.

WHERE状态NOT IN的国家或公司NOT IN公司

仿佛要么是真的,那么公司+状态的该员工的组合是不是排除一个。

鉴于这种情况,你可以如下面这条命令:

$qb = $this->getEntityManager()->createQueryBuilder(); 

    $excludedCompanies = ['company1', 'another company', 'company etc']; 
    $excludedStates = ['state1', 'another state', 'state etc']; 

    return $qb->select('e.company, e.state') 
     ->from('YourBundle:Employee', 'e') 
     ->where($qb->expr()->notIn('e.company', ':excludedCompanies')) 
     ->orWhere($qb->expr()->notIn('e.state', ':excludedStates')) 
     ->setParameter('excludedCompanies', $excludedCompanies) 
     ->setParameter('excludedStates', $excludedStates) 
     ->groupBy('e.company') 
     ->addGroupBy('e.state') 
     ->getQuery() 
     ->getResult() 
    ; 
+0

坦克!相信两个名单的联合“不在”不会结合领域。 @理查德 – jotamolas

+0

例如,如果我有“巴黎,顶点s.a.”和“伦敦,自由之家”当您输入新行“paris,liberty s.a”时,查询不会返回它。 – jotamolas