这是我想要的查询:
SELECT * FROM (SELECT * FROM counter ORDER BY id DESC) AS x GROUP BY campaign_id
但是我找不到在Symfony应用程序中表达这种方法的方法。在Doctrine中使用像这样的子查询的正确方法是什么?
这一个:
$query = $em->createQuery('SELECT c
FROM InstacountInstacountBundle:Counter c
GROUP BY c.campaign');
$counts = $query->getResult();
工作正常,但我只想要我小组中的最新记录。谢谢你的帮助!
答案 0 :(得分:0)
SELECT x.*
FROM counter x
JOIN
( SELECT campaign_id, MAX(id) max_id FROM counter GROUP BY campaign_id ) y
ON y.campaign_id = x.campaign_id
AND y.max_id = x.id;