当前位置: 代码迷 >> Sql Server >> 帮忙翻译下SQL语句解决方案
  详细解决方案

帮忙翻译下SQL语句解决方案

热度:73   发布时间:2016-04-27 20:47:44.0
帮忙翻译下SQL语句
declare   @sql   varchar(8000)
set   @sql   =   'select   stuid   as   学号,stuname   as   姓名 '
select   @sql   =   @sql   +   '   ,   max(case   lessionname   when   ' ' '   +   lessionname   +   ' ' '   then   score   else   null   end)  
[ '   +   lessionname   +   '] '
from   (select   distinct   lessionname   from   (select   a.stuid   ,   b.stuname   ,   c.lessionname   ,  
a.score   from   stu_lession   c,   stu_profile   b,   stu_score   a   where   a.stuid   =   b.stuid   and   a.lessionid   =   c.lessionid)   t   )
as   a
set   @sql   =   @sql   +   '   from   (select   a.stuid   ,   b.stuname   ,   c.lessionname   ,   a.score   from   stu_lession   c,  
stu_profile   b,   stu_score   a   where   a.stuid   =   b.stuid   and   a.lessionid   =   c.lessionid)   t   group   by   stuid,stuname '
exec(@sql)  

翻译成一个完整的SQL语句,[email protected]   直接写那种

------解决方案--------------------
declare @sql varchar(8000)
set @sql = 'select stuid as 学号,stuname as 姓名 '
select @sql = @sql + ' , max(case lessionname when ' ' ' + lessionname + ' ' ' then score else null end)
[ ' + lessionname + '] '
from (select distinct lessionname from (select a.stuid , b.stuname , c.lessionname ,
a.score from stu_lession c, stu_profile b, stu_score a where a.stuid = b.stuid and a.lessionid = c.lessionid) t )
as a
set @sql = @sql + ' from (select a.stuid , b.stuname , c.lessionname , a.score from stu_lession c,
stu_profile b, stu_score a where a.stuid = b.stuid and a.lessionid = c.lessionid) t group by stuid,stuname '

print @sql --------------加这个你就可以看到的了!


exec(@sql)

  相关解决方案