如何在doctrine2 QB或DQL中执行此操作。
SELECT * FROM
(
按时间戳desc从my_table
顺序中选择*
)作为my_table_tmp
分组catid
按nid desc命令
答案 0 :(得分:0)
我认为您的查询与以下内容相同:
SELECT *
FROM my_table
GROUP BY catid
HAVING timestamp = MAX(timestamp)
ORDER BY nid DESC
;
如果它是正确的,那么你应该能够:
$qb->select('e')
->from('My\Entities\Table', 'e')
->groupBy('e.catid')
->having('e.timestamp = MAX(e.timestamp)')
->orderBy('nid', 'DESC')
;
或者,直接使用DQL:
SELECT e
FROM My\Entities\Table e
GROUP BY e.catid
HAVING e.timestamp = MAX(e.timestamp)
ORDER BY e.nid DESC
;
希望这有帮助并且有效! ;)