我的一个专栏叫。我不能改名字,因为不是我做的。 我是否允许做一些像SELECT from TableName或有一个特殊的语法,以避免SQL Server混淆?
当前回答
在Apache Drill中,使用反引号:
select `from` from table;
其他回答
如果是在PostgreSQL中,在名字周围使用双引号,比如:
select "from" from "table";
注意:PostgreSQL内部自动将所有不带引号的命令和参数转换为小写。命令和标识符不区分大小写。sEleCt * from tAblE;解释为select * from table;。然而,双引号内的参数是原样使用的,因此是区分大小写的:select * from "table";and select * from "Table";从两个不同的表获取结果。
在Apache Drill中,使用反引号:
select `from` from table;
简单的解决方案
假设列名是from;因此,查询中的列名可以通过表别名引用
Select * from user u where u.from="US"
你可以像这样把你的列名放在括号里:
Select [from] from < ur_tablename>
Or
放入一个临时表,然后随意使用。 例子:
Declare @temp_table table(temp_from varchar(max))
Insert into @temp_table
Select * from your_tablename
这里我只是假设your_tablename只包含一列(即from)。
下面的方法会很有效:
SELECT DISTINCT table.from AS a FROM table