为列添加别名的不同方法
之间有什么区别
select empName as EmployeeName from employees
两者
select EmployeeName = empName from employees
从技术角度来看, ?不确定这是否只是 SQL Server 特定的。
感谢您的回答。
What is the difference between
select empName as EmployeeName from employees
versus
select EmployeeName = empName from employees
from a technical point of view. Not sure if this is just SQL server specific or not.
Appreciate your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我更喜欢第一个,因为第二个不可移植 -
要么是语法错误(至少在 SQLite 和 Oracle 中),要么它可能不会给你你所期望的(比较两列 EmployeeName 和 empName 并返回比较结果)结果为布尔值/整数),而
与我首选的变体相同
。
I'd prefer the first one, since the second one is not portable -
is either a syntax error (at least in SQLite and Oracle), or it might not give you what you expect (comparing two columns EmployeeName and empName and returning the comparison result as a boolean/integer), whereas
is the same as
which is my preferred variant.
第二种语法的主要优点是它允许列别名全部排列起来,这对于长表达式来说是有益的。
The main advantage of the second syntax is that it allows the column aliases to be all lined up which can be of benefit for long expressions.
我不认为技术上有什么区别。主要是优惠。我选择第二个,因为它更容易在大型查询中发现列,特别是在查询正确缩进的情况下。
I don't think there's a technical difference. Its mainly preferential. I go for the second as its easier to spot columns in big queries, especially if the query is properly indented.