这个页面中的mysql语句报错,问题在哪里呢? https://blog.csdn.net/d_x_program/article/details/9082323 -- 建表: create table tb ( Name varchar(10) , Subject varchar(10) , Result int ) -- 插入数据: insert into tb values ('张三' , '语文' , 74), ('张三' , '数学' , 83), ('张三' , '物理' , 93), ('李四' , '语文' , 74), ('李四' , '数学' , 84), ('李四' , '物理' , 94); --报错SQL文本: 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) |
最佳回答 |
||||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|