Sql纵转横

select   distinct  Sub_name  as  Sub_name,a.Sub_Code 
into  #temptin
from  t_ExamSubject a,t_SubjectManage b
where  a.Exa_Code  =   ' 2 '
and  a.Sub_Code  =  b.Sub_Code
order   by  a.Sub_Code;

select  a. * ,stu_Name,sub_Name 
into  #tempMain
from  t_resultManage a,t_StudentManage b,t_subjectManage c 
where  a.Stu_Code  =  b.Stu_Code  and  a.Sub_code  =  c.Sub_code

declare   @sql   varchar ( 8000 )
set   @sql   =   ' select stu_Name as 学生姓名 ' ;
select   @sql   =   @sql   +   ' ,max(case sub_Name 
when 
''' + sub_Name + '''  then sub_numeric end) [ ' + sub_Name + ' ] '  
from  #temptin; set   @sql   =   @sql + '  from #tempMain group by stu_code,stu_name order by stu_code ' ;

exec ( @sql )
drop   table  #temptin
drop   table  #tempmain

横转竖
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值