Mysql:按排名返回orderBy

Mysql:按排名返回orderBy,mysql,doctrine,Mysql,Doctrine,有没有办法将Mysql orderBy排名作为结果记录的一部分返回 例如,假设我有一个注释表,在该表中我查询的结果按以下顺序排列: comment\u rating和comment\u length,使用orderBy('r.comment\u rating*r.comment\u length') 现在,我希望结果记录包含各自的comment\u rating*comment\u length计算值 这可能吗 编辑:另外,如果我这样做并且对orderBy使用相同的算法,doctrine是否会执

有没有办法将Mysql orderBy排名作为结果记录的一部分返回

例如,假设我有一个注释表,在该表中我查询的结果按以下顺序排列:

comment\u rating
comment\u length
,使用
orderBy('r.comment\u rating*r.comment\u length')

现在,我希望结果记录包含各自的
comment\u rating*comment\u length
计算值

这可能吗

编辑:另外,如果我这样做并且对orderBy使用相同的算法,doctrine是否会执行两次排名计算?

尝试以下方法:

SELECT <yourFields>, (r.comment_rating * r.comment_length) AS Rating FROM ...
选择(r.comment\u rating*r.comment\u length)作为来自的评级。。。

文档: 试试这个:

SELECT <yourFields>, (r.comment_rating * r.comment_length) AS Rating FROM ...
选择(r.comment\u rating*r.comment\u length)作为来自的评级。。。

文档:
你是说:

SELECT *, (comment_rating * comment_length) AS ranking FROM comment ORDER BY ranking DESC
编辑

我没有使用过教义,但在快速浏览了一下之后,我想它会是这样的:

$q = Doctrine_Query::create()
    ->select('*, (comment_rating * comment_length) AS ranking')
    ->from('comment')
    ->orderBy('ranking');
$comments = $q->execute();

你是说:

SELECT *, (comment_rating * comment_length) AS ranking FROM comment ORDER BY ranking DESC
编辑

我没有使用过教义,但在快速浏览了一下之后,我想它会是这样的:

$q = Doctrine_Query::create()
    ->select('*, (comment_rating * comment_length) AS ranking')
    ->from('comment')
    ->orderBy('ranking');
$comments = $q->execute();

你所需要做的就是包括

(comment_rating*comment_length) as comment_ranking

在选择字段列表中。

您需要做的就是包括

(comment_rating*comment_length) as comment_ranking
SELECT
  comment_rating,
  comment_length,
  comment_rating*comment_length AS comment_rank
FROM
  tablename
ORDER BY
  comment_rank;
在选择字段列表中。

尝试以下操作:

SELECT
  comment_rating,
  comment_length,
  comment_rating*comment_length AS comment_rank
FROM
  tablename
ORDER BY
  comment_rank;
Select comment_rating, comment_length, 
       (comment_rating * comment_length) as rat_len 
From comment 
OrderBy rat_len
试试这个:

Select comment_rating, comment_length, 
       (comment_rating * comment_length) as rat_len 
From comment 
OrderBy rat_len

我将如何使用条令?@Whamiscore没有使用条令,但请查看我的更新答案,并让我知道它是否有效。我将如何使用条令?@Whamiscore没有使用条令,但请查看我的更新答案,让我知道它是否有效。如果我这样做,doctrine是否执行两次排名计算,并且对orderBy使用相同的算法?如果我这样做,doctrine是否执行两次排名计算,并且对orderBy使用相同的算法?