MySQL-我们可以按列位置而不是名称排序吗? [英] MySQL - Can we order by column position instead of name?

查看:152
本文介绍了MySQL-我们可以按列位置而不是名称排序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过Google,但是找不到.我们可以使用字段的位置在MySQL中订购吗?

I've looked on Google but couldn't find it. Can we order in MySQL using field's position ?

假设我得到了字段ID | FirstName | LastName | Age,但是我想按字段4进行订购,是否可以像ORDER BY FieldPos4那样对Age进行订购?我还没办法找到有关的东西.

Let's say I got fields ID | FirstName | LastName | Age but I want to order by field 4, could I do something like ORDER BY FieldPos4 to order on Age ? I have not manage to find something about that.

谢谢.

推荐答案

您可以按位置(从1开始)引用列:

You can refer to the columns by position (1-based):

ORDER BY 4

来自 文档 (重点是我的):

From the documentation (emphasis mine):

选择用于输出的列可以在ORDER BY和GROUP中引用 使用列名称,列别名或列位置的BY子句. 列位置是整数,以1开头

Columns selected for output can be referred to in ORDER BY and GROUP BY clauses using column names, column aliases, or column positions. Column positions are integers and begin with 1

这篇关于MySQL-我们可以按列位置而不是名称排序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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