哇,union的优先级很高嘛

81 阅读1分钟

原来,union的优先级很高。比如

select stdname,[subject]='化学',化学 as score  from #student2 
union all 
select stdname,[subject]='数学',数学 as score  from #student2 
union all 
select stdname,[subject]='物理',物理 as score  from #student2 
union all 
select stdname,[subject]='语文',语文 as score  from #student2 
order by stdname,[subject]


等同于

select * from(
select stdname,[subject]='化学',化学 as score  from #student2 
union all 
select stdname,[subject]='数学',数学 as score  from #student2 
union all 
select stdname,[subject]='物理',物理 as score  from #student2 
union all 
select stdname,[subject]='语文',语文 as score  from #student2 
) as a
order by stdname,[subject]


\