如何获取使用 DQL(Doctrine) 查询的结果的行号

How can I get the row number of results querying with DQL(Doctrine)

示例:SELECT 标题,ROW_NUM 来自文章 ORDER BY count_read。 ROW_NUM 应该替换成什么?

我不喜欢在得到结果后通过程序生成索引,因为我想通过查询上面的示例 DQL 将结果数据插入 table Rank。

我想实现的可能是:

"INSERT INTO RANK r (title, index, lastIndex)
SELECT title,ROW_NUM,(SELECT index FROM RANK WHERE id = :id - 1) FROM article ORDER BY count_read"

提前致谢..

我想你可能会像这样使用变量:

"
SET @row_num := 1;
INSERT INTO RANK r (title, index, lastIndex)
SELECT title, 
       (@row_num := @row_num + 1),
       (SELECT index FROM RANK WHERE id = :id - 1) 
FROM article ORDER BY count_read
"