此 SQL 查询是否有性能损失?
select fullname, address from (select (name + ' ' + lastname) as fullname, address from mytable) as tab
与之比较:
select (name + ' ' + lastname) as fullname, address from mytable
也许你会想.. 为什么我要这样做,原因是因为 SQL Server 不允许在 group by 中使用别名,所以使用签名子查询我可以这样做
select fullname, address from (select (name + ' ' + lastname) as fullname, address from mytable) as tab group by fullname
代替
select (name + ' ' + lastname) as fullname, address from mytable group by name + ' ' + lastname
这只是一个示例,其中 alias is 和 alias 的基本连接,但连接更复杂,将其重写为 group 子句真的很难看。