-- 学号 姓名 语文 数学 英语 总分 平均分
select 学号=stuid,姓名=[name],
语文=isnull(min(case when subject='语文' then score end),0),
数学=isnull(min(case when subject='数学' then score end),0),
英语=isnull(min(case when subject='英语' then score end),0),
总分=sum(score),
平均分=avg(score)
from scores group by stuid,[name]
发个例子你 表结构:学号,科目,分数 横向显示信息
declare @name varchar(50)
declare @month varhcar(10)
declare @day varchar(10)
declare cursor ppp
as
select name,month day
from tb1
open ppp
fetch next from ppp into @name,@month,@day
while(@@fetch_status=0)
{
insert into tb2(names,date)
values(@name,@month+@day)
fetch next from ppp into @name,@month,@day)
}
collapse ppp
用游标实现的,放在定义的存储过程里!!!