mysql:按数字引用列
我想给列别名,但不知道它们的名称,而只知道它们在表中的编号。
像这样的事情:
select firstColumn as myId, secondColumn as myName, thirdColumn as myLastName
我不知道列的实际名称
(我知道这种需求听起来很奇怪。是的,我可以知道列的名称。这是一个技术问题,如果您知道技术答案,请回答,无论动机如何!)
I want to give columns aliases without knowing their names, but only their number in the table.
Something like this:
select firstColumn as myId, secondColumn as myName, thirdColumn as myLastName
where I don't know the actual names of the columns
(I understand that the need sounds strange. And yes I can know the names of the columns. This is a technical question, please answer if you know the technical answer, regardless of the motivation. Thank you!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的最接近的是使用 INFORMATION_SCHEMA.COLUMNS 从序数位置查找列名称。我知道这不是您所要求的,但我认为这可能是您能得到的最接近的。例如,您可以构建一个包含第一、第二和第五列的 select 语句,如下所示:
The closest you could do is use INFORMATION_SCHEMA.COLUMNS to find the column name from the ordinal position. I realize this isn't what you asked for, but I think it may be as close as you can get. For instance, you could build a select statement having the 1st, 2nd and 5th columns as follows: