当前位置: 代码迷 >> Sql Server >> 这句SQL话语是什么意思
  详细解决方案

这句SQL话语是什么意思

热度:91   发布时间:2016-04-24 21:21:48.0
这句SQL语句是什么意思?
select SUM([price]) from (select * from table1 union all select * from table2) a
最后加一个a表示什么意思?

------解决方案--------------------
起别名的,不加会报错的
------解决方案--------------------
 select SUM(a.[price]) from (select * from table1 union all select * from table2) as a 

取的别名。。顶楼上
------解决方案--------------------
 (select * from table1 union all select * from table2) 结果的别名 


------解决方案--------------------
引用:
 select SUM(a.[price]) from (select * from table1 union all select * from table2) as a 

取的别名。。顶楼上


------解决方案--------------------
引用:
select SUM([price]) from (select * from table1 union all select * from table2) a
最后加一个a表示什么意思?


from后面的这部分(select * from table1 union all select * from table2) ,
是一个派生表,由:
select * from table1 
union all 
select * from table2
组成的数据,而派生表必须要取个别名,不加就会报错。
  相关解决方案