mysql& php:查询结果的临时/虚拟ID?

时间:2010-10-31 16:43:19

标签: php mysql temp-tables

我想知道是否可以为查询结果分配临时/虚拟ID?

例如,我将此作为我的查询,

SELECT 

pg_id AS ID,
pg_url AS URL,
pg_title AS Title,
pg_content_1 AS Content

FROM root_pages

ORDER BY pg_created DESC

输出:

ID  URL     Title   Content 
53  a       A       xxx 
40  b       B       xxx 
35  c       C       xxx  

你可以看到ID之间的差距 - 它们非常不整洁。我想知道我是否可以创建一个虚拟列或其他东西,以便我有下面的输出,

ID  URL     Title   Content  Virtual ID
53  a       A       xxx      3
40  b       B       xxx      2
35  c       C       xxx      1 

来自下面的查询,

SELECT 

pg_id AS ID,
pg_url AS URL,
pg_title AS Title,
pg_content_1 AS Content

FROM root_pages

ORDER BY virtual_id DESC 

有可能??

谢谢!

1 个答案:

答案 0 :(得分:0)

如果你仍然坚持获得每一行的位置 看看这个答案

MySQL get row position in ORDER BY