Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql和php:查询结果的临时/虚拟ID?_Php_Mysql_Temp Tables - Fatal编程技术网

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

mysql和php:查询结果的临时/虚拟ID?,php,mysql,temp-tables,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

我想知道是否可以为查询结果分配临时/虚拟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 
有可能吗


谢谢

如果您仍然坚持获取每行的位置 看看这个答案


为什么您需要虚拟id?这样我就可以按虚拟id进行订购?您仍然可以单独使用id?是的,它可以单独使用id。但是当我查询奇数id或偶数id时,它不会输出“正确”,其中MODpg_id,2=1。谢谢。但这是一个单行输出-我恐怕不是我要找的。。。Cheers如果您删除WHERE t.name='Beta',那么您将获得所有行的数据?我尝试将此SELECT COUNT*FROM root_pages作为位置。然后,它为每一行创建一个相同的最新编号…我找到了一个解决方案-感谢您的回复,让我找到了它!: