create table stcj (学号 varchar (5),数学 decimal (12,2), 语文 decimal (12,2),
英语 decimal (12,2), 物理 decimal (12,2) ,化学 decimal (12,2))insert into stcj
select '001',12,45,78,15,12 union
select '002',15,23,15,56,78 union
select '005',56,12,48,52,51declare @str varchar(8000)set @str=''
select @str=@str+'+'+a.name from syscolumns a,sysobjects b where a.id=b.id and b.name='stcj' and a.name<>'学号'
exec ('select distinct 学号,合计='+@str+' from stcj')
英语 decimal (12,2), 物理 decimal (12,2) ,化学 decimal (12,2))insert into stcj
select '001',12,45,78,15,12 union
select '002',15,23,15,56,78 union
select '005',56,12,48,52,51declare @str varchar(8000)set @str=''
select @str=@str+'+'+a.name from syscolumns a,sysobjects b where a.id=b.id and b.name='stcj' and a.name<>'学号'
exec ('select distinct 学号,合计='+@str+' from stcj')
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货