教义 - 来自的子查询
我在 MySQL 中有一个查询:
I have a query in 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
我想用教义来写这个.我怎么能这样做?我写道:
and I want to write this in doctrine. How I can do that? I wrote:
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();
但我不能把它放在从"中按名称排序.
But I can't put it in "from" to sort by name.
推荐答案
这是一个答案:
$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');
相关文章