使用列号而不是名称在mysql中进行选择 [英] SELECT in mysql using column number instead of name

查看:192
本文介绍了使用列号而不是名称在mysql中进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做类似的事情:

Is there any way to do something like :

SELECT * FROM TABLE WHERE COLUMN_NUMBER = 1;

?

推荐答案

如果您的表中有一个名为COLUMN_NUMBER的列,并且您想从表中检索该行包含"1"值的行,则该查询应做到这一点.

If your table has a column named COLUMN_NUMBER and you want to retrieve rows from the table where that column contains a value of '1', that query should do the trick.

我怀疑您要执行的操作是使用别名在选择列表中引用一个表达式.那是不被支持的. WHERE子句中引用列的表达式必须按名称引用该列.

I suspect that what you are trying to do is reference an expression in the select list with an alias. And that is not supported. An expression in the WHERE clause that references a column must reference the column by name.

我们可以使用内联视图玩一些技巧,为表达式赋予别名,但是就WHERE谓词而言,这不是很有效,因为MySQL实现了派生表的方式.并且,在这种情况下,它是必须在外部查询中引用的内联视图中列的名称.

We can play some tricks with inline views, to give an alias to an expression, but this is not efficient in terms of WHERE predicates, because of the way MySQL materializes a derived table. And, in that case, its a name given to the column in the inline view that has to be referenced in the outer query.

这篇关于使用列号而不是名称在mysql中进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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