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

发布于 2024-09-30 04:13:57 字数 764 浏览 4 评论 0原文

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

这可能吗?

谢谢!

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

output:

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

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 

from a query like this below,

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 

is it possible??

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺孤伤于心 2024-10-07 04:13:57

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

MySQL get row position in ORDER BY

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

MySQL get row position in ORDER BY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文