我在 MySQL 中有一个查询:
SELECT * FROM (
SELECT COUNT(*) AS count, t.name AS name
FROM tag t
INNER JOIN video_has_tag v USING (idTag)
GROUP BY v.idTag
ORDER BY count DESC
LIMIT 10
) as tags ORDER BY name
我想把它写成 Doctrine 。我该怎么做?我写道:
Doctrine_Query::create()
->select('COUNT(t.idtag) as count, t.name')
->from('Tag t')
->innerJoin('t.VideoHasTag v')
->groupBy('v.idTag')
->orderBy('count DESC, t.name')
->limit(30)
->execute();
但我不能把它放在“from”中按名字排序。
最佳答案
这是一个答案:
$q = new Doctrine_RawSql();
$q->addComponent('t', 'Tag')
->select('{t.name}, {t.count}')
->from('(SELECT COUNT(*) as count, t.name,t.idtag
FROM Tag t
INNER JOIN Video_Has_Tag v USING(idTag)
GROUP BY v.idTag
ORDER BY count DESC
LIMIT 50) t')
->orderBy('name');
关于php - Doctrine - 来自的子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1869233/