我在Symfony中写了一个查询,它返回一年中每个月的总金额。但是当我试着把它从一个月的数字转换到一个月的名字时,它就会变小
错误:预期的Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS,得到",“
我的密码..。
$resultYearly = $this->getTransactionRepository()
->createQueryBuilder('p')
->select('MONTH(p.transactionDate, \'%b\') AS MonthOfYear, sum(p.amount) Total')
MonthAndYear, sum(p.amount) Total')
->where('p.transactionDate >= :end')
->setParameter('end', new \DateTime('-1 year'))
->groupBy( 'MonthOfYear')
->getQuery()
->getArrayResult();它适用于DATE_FORMAT,但当我使用月份时,它会抛出一个错误。
发布于 2018-11-26 11:10:38
使用
DATE_FORMAT(p.transactionDate,'%b') AS MonthOfYear发布于 2018-11-26 10:51:17
您需要从\'%b\'函数中删除Month部分,因为MONTH函数只接受一个参数,即日期。所以你的代码应该是:
$resultYearly = $this->getTransactionRepository()
->createQueryBuilder('p')
->select('MONTH(p.transactionDate) AS MonthOfYear, sum(p.amount) Total')
MonthAndYear, sum(p.amount) Total')
->where('p.transactionDate >= :end')
->setParameter('end', new \DateTime('-1 year'))
->groupBy( 'MonthOfYear')
->getQuery()
->getArrayResult();https://stackoverflow.com/questions/53479458
复制相似问题