图1-1
我建了图1-1的表,通过写数据库语句将表变成下图2-2形式
       图 2-2
实现的sql语句:
declare @a table(sname nchar(10),china int)
insert into @a
select sname,score
from sscore
where couse='语文'
declare @b table(sname nchar(10),shuxu int)
insert into @b
select sname,score
from sscore
where couse='数学'
select isnull (a.sname,b.sname) 姓名,isnull(a.china,null) 语文,isnull(b.shuxu,null) 数学
from @a a full join @b b
on a.sname=b.sname
或者还可以用这种方法实现,我比较喜欢这种方法
select isnull(a.sname,b.sname) 姓名,
      max (case a.couse when '语文' then a.score else null end) 语文,
     max(case b.couse when '数学' then b.score else null end) 数学
from sscore as a inner join sscore as b
on a.sname=b.sname
group by a.sname,b.sname