我正在使用Symfony 1.4和Doctrine 1.2 ORM构建应用程序.我对ORM的学说很新,并且我已经掌握了它,但我无法解决这个问题.
我有一个用户分数表(mbScoreByGenre),其中一个用户ID可以有一个parent_genre的多个用户分数记录.即 - 很多甚至很多
我的目标是根据给定parent_genre_id和user_id的累积分数查找特定用户的排名.我的排名算法使用子查询,我在构建一个有效的学说查询时遇到了很多麻烦.
这是我对mbScoreByGenre的学说模式
mbScoreByGenre:
actAs:
Timestampable: ~
columns:
id: { type: integer, primary: true, autoincrement: true }
user_id: { type: integer, notnull: true }
genre_id: { type: integer, notnull: true }
parent_genre_id: { type: integer, notnull: true }
score: { type: float, notnull: true, default: 0 }
Run Code Online (Sandbox Code Playgroud)
A.首先我尝试做这样的事情:
$q = Doctrine_Query::create()
->select('((SELECT COUNT(1) AS num
FROM
(SELECT SUM(mbScoreByGenre.score)
WHERE SUM(mbScoreByGenre.score) > SUM(s.score)
AND mbScoreByGenre.parent_genre_id = '.$genre['parent_id'].'
AND s.parent_genre_id = '.$genre['parent_id'].'
GROUP BY mbScoreByGenre.user_id
) …
Run Code Online (Sandbox Code Playgroud)