我从NativeQuery生成一个SQL,结果是sql:
按年份( created_at )、月( created_at )、日(Created_at)从属性中选择计数(Id)作为tot、created_at在'20120501000000‘和'20120521235959’之间;
这是我的ResultSetMapping:
$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
$rsm->addEntityResult('Entity\Property', 'p');
$rsm->addFieldResult('p','count(id)','tot'); // <-- this don't work
$rsm->addFieldResult('p','created_at','created_at');在mysql上直接运行上述查询的结果是可以的:
tot created_at
11 2012-05-02 11:23:25
11 2012-05-08 14:56:40
152 2012-05-16 14:43:46
5 2012-05-17 16:26:31
29 2012-05-18 14:55:33但是结果数组tot别名不存在!!
问题是:
如何正确地为count(id)设置
发布于 2012-05-29 12:49:03
我试着:
$rsm->addFieldResult('p', 'tot', 'tot');作为您的列,并将其重命名为带有COUNT(id) AS tot的。如果删除tot别名,则可以使用原始代码:
$rsm->addFieldResult('p', 'COUNT(id)', 'tot');https://stackoverflow.com/questions/10691139
复制相似问题