将表别名与“Where”组合起来在 Informix 中
我在 Informix 上使用带有 where 部分的表别名时遇到严重问题。
所以我可以运行:
SELECT ColA, ColB
FROM Table1 AS TestTable
但是一旦我尝试这个:
SELECT ColA, ColB
FROM Table1
WHERE type = 'A' AS TestTable
..它就行不通。当我尝试使用 WHERE 部分连接表时,也会发生同样的情况。
我正在尝试优化这个问题的查询,所以我正在尝试不要使用临时表。
I'm facing serious problems using table aliases on Informix with a where part.
So I can run:
SELECT ColA, ColB
FROM Table1 AS TestTable
But as soon as i try this:
SELECT ColA, ColB
FROM Table1
WHERE type = 'A' AS TestTable
..it wouldn't work. The same happens when I try to join tables with a WHERE part.
I'm trying to optimize a query from this Question so I'm trying not to work with temporary tables.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您正在尝试获得相当于 Oracle 的内联视图。语法是:
I assume you are trying to get the equivalent of Oracle's inline views. Syntax is:
您可以为选择列表中的列或 FROM 子句中的表(或子查询)添加别名。
因此,您可以写:
或者您可以写:
请注意,在此查询中,名称 TestTable 实际上并未使用。更复杂的子查询很可能会使用别名(尽管我非常喜欢短别名 - 比使用别名的表名短的别名)。
You can alias columns in the select-list or tables (or sub-queries) in the FROM clause.
Therefore, you'd write:
or you'd write:
Note that in this query, the name TestTable does not actually get used. A more complex sub-query might well make use of an alias (though I have a strong preference for short aliases — aliases that are shorter than the table name that is aliassed).
据我所知,任何数据库系统都不允许尝试在Where子句中使用别名。您可以使用
Select ... Into
将 Select 语句的结果推送到表中,如下所示:但是,您需要使用单独的 SQL 语句来使用
Table2
在上面的例子中。另一种选择是使用公共表表达式,我相信 Informix 支持该表达式:As far as I know, trying to use an alias in a Where clause is not permitted in any database system. You can push the results of a Select statement into a table using
Select ... Into
like so:However, you would then need to use a separate SQL statement to use
Table2
in the above example. The other choice is to use a common-table expression which I believe is supported by Informix: