0

我有以下字段的表操作:

  • idAction
  • Cloture
  • 日期

我想循环并显示所有idAction在我的 DB +idAction中的所有列表,并按Cloture = 0相同日期分组(两者)。

我尝试了以下方法。但它不起作用。谁能帮我?

$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');
4

1 回答 1

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)

您不能在选择列表中的子查询\相关查询中选择超过 1 列,这可能在错误消息中显示给您。

编辑:最好这样做:

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)
于 2017-09-25T15:55:12.350 回答