名称 fs1 fs2 fs3 fs4 fs5 hj
绩效考核员 0 0 0 1 0
网络管理员 0 1 0 0 0
新产品开发员 0 0 0 0 2
网络管理员 4 0 0 0 0
新产品开发员 4 4 4 0 0
绩效考核员 0 0 0 1 0
网络管理员 0 1 0 0 0
新产品开发员 0 0 0 0 2
网络管理员 4 0 0 0 0
新产品开发员 4 4 4 0 0
insert into @t select '绩效考核员',0,0 ,0 ,1 ,0
union all select '网络管理员' ,0 ,1 ,0 ,0 ,0
union all select '新产品开发员' ,0 ,0 ,0 ,0 ,2
union all select '网络管理员' ,4 ,0 ,0 ,0 ,0
union all select '新产品开发员' ,4 ,4 ,4 ,0 ,0select 名称,fs1,fs2,fs3,fs4,fs5,(fs1+fs2+fs3+fs4+fs5) as hj from @t group by 名称,fs1,fs2,fs3,fs4,fs5
insert into tb select '绩效考核员',0,0 ,0 ,1 ,0
union all select '网络管理员' ,0 ,1 ,0 ,0 ,0
union all select '新产品开发员' ,0 ,0 ,0 ,0 ,2
union all select '网络管理员' ,4 ,0 ,0 ,0 ,0
union all select '新产品开发员' ,4 ,4 ,4 ,0 ,0declare @sql varchar(1000)
declare @sql1 varchar(1000)
set @sql=''
select @sql=@sql+','+name from syscolumns where id=object_id('tb') and name<>'名称' order by colid
set @sql1=stuff(@sql,1,1,'')
select @sql=stuff(@sql,1,1,'')+',sum('+stuff(replace(@sql,',','+'),1,1,'')+') as hj'
set @sql='select '+@sql+' from tb group by '+@sql1
exec(@sql)drop table tb
create table tb(名称 varchar(20),fs1 int,fs2 int,fs3 int,fs4 int,fs5 int)
insert into tb select '绩效考核员',0,0 ,0 ,1 ,0
union all select '网络管理员' ,0 ,1 ,0 ,0 ,0
union all select '新产品开发员' ,0 ,0 ,0 ,0 ,2
union all select '网络管理员' ,4 ,0 ,0 ,0 ,0
union all select '新产品开发员' ,4 ,4 ,4 ,0 ,0declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+name from syscolumns where id=object_id('tb') and name<>'名称' order by colid
select @sql='select '+stuff(@sql,1,1,'')+',sum('+stuff(replace(@sql,',','+'),1,1,'')+') as hj from tb group by '+stuff(@sql,1,1,'')
exec(@sql)drop table tb
insert into tb select '绩效考核员',0,0 ,0 ,1 ,0
union all select '网络管理员' ,0 ,1 ,0 ,0 ,0
union all select '新产品开发员' ,0 ,0 ,0 ,0 ,2
union all select '网络管理员' ,4 ,0 ,0 ,0 ,0
union all select '新产品开发员' ,4 ,4 ,4 ,0 ,0declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+name from syscolumns where id=object_id('tb') and name<>'名称' order by colid
select @sql='select 名称,'+stuff(@sql,1,1,'')+',sum('+stuff(replace(@sql,',','+'),1,1,'')+') as hj from tb group by 名称,'+stuff(@sql,1,1,'')
exec(@sql)drop table tb
被评价岗位 varchar 50 1
spjfs varchar 50 1
合计分数 numeric 17 1
数据记录被评价岗位 spjfs 合计分数
网络管理员 创新性 4
新产品开发员 创新性 4
网络管理员 工作负荷 1
新产品开发员 工作负荷 4
新产品开发员 管理决策 4
绩效考核员 计算机和外语水平 1
新产品开发员 自主权利 2
我给你的是经过行转列后的,然后求每行的合计数
名称 fs1 fs2 fs3 fs4 fs5 ....fsn hj
绩效考核员 0 0 0 1 0
网络管理员 0 1 0 0 0
新产品开发员 0 0 0 0 2
网络管理员 4 0 0 0 0
新产品开发员 4 4 4 0 0
insert into tb select '绩效考核员',0,0 ,0 ,1 ,0,null
union all select '网络管理员' ,0 ,1 ,0 ,0 ,0,null
union all select '新产品开发员' ,0 ,0 ,0 ,0 ,2,null
union all select '网络管理员' ,4 ,0 ,0 ,0 ,0,null
union all select '新产品开发员' ,4 ,4 ,4 ,0 ,0,nulldeclare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+name from syscolumns where id=object_id('tb') and name not in('名称','hj') order by colid
select @sql='select 名称,'+stuff(@sql,1,1,'')+',sum('+stuff(replace(@sql,',','+'),1,1,'')+') as hj from tb group by 名称,'+stuff(@sql,1,1,'')
exec(@sql)drop table tb
--不用sum的字段写在not in的后面