使用不带AS的别名

时间:2018-12-03 21:08:11

标签: postgresql alias

我从参考笔记中发现了以下查询,并且可以看到将lineitem表命名为l1,并将lineitem表命名为l2

select avg(l_extendedprice) from lineitem l1
where l_extendedprice =
(select min(l_extendedprice) from lineitem l2
where l1.l_orderkey = l2.l_orderkey);

这是有效的别名方法,无需显式使用AS吗?如果这不是Postgres中的别名,这是什么约定?

1 个答案:

答案 0 :(得分:2)

SQL标准允许您使用带或不带AS的别名。

区别在于,如果没有AS,则不能使用PostgreSQL关键字作为别名,请参见the documentation。因此,始终使用AS更为安全。