mysql& php:查询结果的临时/虚拟ID?
我想知道是否可以为查询结果分配临时/虚拟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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你还坚持获取每一行的位置
看看这个答案
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