mysql &php:查询结果的临时/虚拟ID? [英] mysql & php: temporary/ virtual ids for query results?

查看:46
本文介绍了mysql &php:查询结果的临时/虚拟ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wonder if it is possible to assign temporary/ virtual IDs for a query result?

例如,我将此作为查询,

For instance, I have this as my query,

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 之间的间隙 - 它们非常凌乱.我想知道我是否可以制作一个虚拟列或其他东西,以便我有下面的输出,

you can see the the gap between the IDs - they are very untidy. I wonder if I can make a virtual column or something so that I have the output below,

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 

有可能吗??

谢谢!

推荐答案

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

If you still persist on getting the position of each row take a look at this answer

MySQL 获取 ORDER BY 中的行位置

这篇关于mysql &php:查询结果的临时/虚拟ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆