select a.专业,b.考试课程1
from tablename a,
(select 考试课程1 from tablename
union
select 考试课程2 from tablename) b
where a.考试课程1 = b.考试课程1 or a.考试课程2 = b.考试课程1
order by a.专业
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+' union all select 专业,考试课程='+name+' from 表'
from syscolumns where object_id('表')=id and name like '考试课程%'