我的表操作包含以下字段:
我想循环浏览并显示所有idAction
在我的数据库中的列表+ idAction
与Cloture = 0
分组相同的日期(两者都有)。< / p>
我试过以下方法。但它不起作用。任何人都可以帮助我吗?
$query = $this->getEntityManager()->createQuery(
'SELECT COUNT(a.idAction) AS nmbreAction , week(a.dateOuverture) AS week,( SELECT COUNT(c.idAction) , week(c.dateOuverture) FROM ActionActionBundle:Action c
WHERE c.cloture = 0 ) AS nmbreRetard FROM ActionActionBundle:Action a
GROUP BY week');
答案 0 :(得分:0)
SELECT COUNT(a.idAction) AS nmbreAction ,
week(a.dateOuverture) AS week,
(SELECT COUNT(c.idAction)
FROM ActionActionBundle:Action c
WHERE c.cloture = 0
and week(c.dateOuverture) = week(a.dateOuverture)) AS nmbreRetard
FROM ActionActionBundle:Action a
GROUP BY week(a.dateOuverture)
您无法在选择列表中的子查询\相关查询中选择多于一列,这可能会在错误消息中显示给您。
编辑:更好的是:
SELECT COUNT(a.idAction) AS nmbreAction ,
week(a.dateOuverture) AS week,
COUNT(CASE WHEN a.cloture = 0 THEN 1 END) as nmbreRetard
FROM ActionActionBundle:Action a
GROUP BY week(a.dateOuverture)