首页 新闻 会员 周边 捐助

SQL 动态列转行

0
[已解决问题] 解决于 2018-01-26 16:21

declare @sql varchar(8000)
set @sql ='select Name as 姓名'
select @sql = @sql+' , max(case Subject when ''' + Subject + ''' then Result else 0 end) Subject'
from (select distinct Subject from tb) as a
set @sql = @sql + ' from tb group by name'
exec(@sql)

  这个Sql 语句 哪里错了  ,找了半天也没找出来,求大神 帮下忙  

蓝天N的主页 蓝天N | 菜鸟二级 | 园豆:204
提问于:2017-10-31 10:48
< >
分享
最佳答案
0

from (select distinct Subject from tb) as a

这个你怎么在单引号外?

奖励园豆:5
Daniel Cai | 专家六级 |园豆:10424 | 2017-10-31 11:16

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare @sql varchar(800)
set @sql ='select Name as 姓名'
select @sql = @sql' at line 1  

运行之后的错误 ,不知道哪里写错了

蓝天N | 园豆:204 (菜鸟二级) | 2017-10-31 11:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册