sql语句from (select distinct Subject from tb) as什么意思

declare @sql varchar(8000)
set @sql = 'select Name as ' + '姓名'
select @sql = @sql + ' , max(case Subject when ''' + Subject + ''' then Result else 0 end) [' + Subject + ']'
from (select distinct Subject from tb) as a
set @sql = @sql + ' from tb group by name'
exec(@sql)
from (select distinct Subject from tb) as a

as a必须要么。可不可以不要

一只甜甜圈
浏览 1082回答 2
2回答

UYOU

把子查询:select distinct Subject from tb的结果作为一个表a来使用(理解成临时视图a也可以)关于sql语句中 from 子表伪名的问题:Oracle支持:select * from (xxx)select * from (xxx) aSQL Server和db2支持:select * from (xxx) as aselect * from (xxx) asybase 都不支持,另有写法所以,最好写成:select * from (xxx) a
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server