【发布时间】:2023-04-01 21:42:01
【问题描述】:
我想按生日列出我的用户,所以是月份和日期,而不是年份。
我有这个问题
SELECT *
FROM user
WHERE birthDate IS NOT NULL
GROUP BY MONTH(birthDate), DAY(birthDate)
但我不知道如何将它与 Symfony 和 Doctrine 一起使用。 我试过了
$result = $em->getRepository("AcmeApplicationBundle:SecurityServiceUser")
->createQueryBuilder('user')
->where('user.birthDate IS NOT NULL')
->groupBy('MONTH(user.birthDate), DAY(user.birthDate)')
->getQuery()
->getResult();
和
$result = $em->getRepository("AcmeApplicationBundle:SecurityServiceUser")
->createQueryBuilder('user')
->where('user.birthDate IS NOT NULL')
->groupBy('MONTH(user.birthDate)')
->groupBy('DAY(user.birthDate)')
->getQuery()
->getResult();
但在这两种情况下我都有一个错误
[语义错误] line 0, col 165 near 'MONTH(birthDate),':错误:无法按未定义的标识或结果变量分组。
【问题讨论】:
-
为什么会有这个查询?
-
你安装了 [github.com/beberlei/DoctrineExtensions](Doctrine Extensions) 吗?
标签: php mysql sql symfony doctrine-orm