现在的位置: 首页 > 综合 > 正文

哇,union的优先级很高嘛

2013年10月10日 ⁄ 综合 ⁄ 共 540字 ⁄ 字号 评论关闭

原来,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]

抱歉!评论已关闭.