gpt4 book ai didi

php - Doctrine - 来自的子查询

转载 作者:IT老高 更新时间:2023-10-29 00:21:56 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com