求Sql查询语句
表一:   
 姓名      编号   
 张三      0001 
 张三      0002                
 李四      0003 
 王五      0004 
 赵六      0005 
 赵六      0006 
 赵六      0007   
 表二:   
 b1   
 年份      0001      0002      0003   0004      0005      0006      0007 
 2005            1               2               3            4               5               6               7 
 2006            8               9               10         11            12            13            14 
 2007            15            16            17         18            19            20            21   
 想得到这样的输出:   
 姓名      编号      2007   
 张三      0001            31 
 李四      0003            10 
 王五      0004            11 
 赵六      0005            60
------解决方案--------------------那李四 和王五应该是17 18 啊
------解决方案----------------------创建测试环境 
 create table a(姓名 varchar(10), 编号 varchar(10)) 
 create table b(年份 int, [0001] int,  [0002] int, [0003] int,[0004]  int,[0005]  int 
       ,[0006]  int,[0007] int) 
 --插入测试数据 
 insert a(姓名,编号) 
 select  '张三 ', '0001 ' union all 
 select  '张三 ', '0002 ' union all 
 select  '李四 ', '0003 ' union all 
 select  '王五 ', '0004 ' union all 
 select  '赵六 ', '0005 ' union all 
 select  '赵六 ', '0006 ' union all 
 select  '赵六 ', '0007 ' 
 insert b(年份,[0001],[0002],[0003],[0004],[0005],[0006],[0007]) 
 select  '2005 ', '1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ' union all 
 select  '2006 ', '8 ', '9 ', '10 ', '11 ', '12 ', '13 ', '14 ' union all 
 select  '2007 ', '15 ', '16 ', '17 ', '18 ', '19 ', '20 ', '21 '   
 --求解过程 
 select a.姓名,sum(b.num) as [2007] 
 from a 
 join (  
       select 年份,[0001] as num, '0001 ' as 编号 from b union all 
       select 年份,[0002], '0002 ' as 编号 from b union all 
       select 年份,[0003], '0003 ' as 编号 from b union all 
       select 年份,[0004], '0004 ' as 编号 from b union all 
       select 年份,[0005], '0005 ' as 编号 from b union all 
       select 年份,[0006], '0006 ' as 编号 from b union all 
       select 年份,[0007], '0007 ' as 编号 from b  
 ) b on a.编号 = b.编号 
 where b.年份 = 2007 
 group by a.姓名 
 order by a.姓名     
 --删除测试环境 
 drop table a,b   
 /*--测试结果 
 姓名         2007         
 ---------- -----------  
 李四         17 
 王五         18 
 张三         31 
 赵六         60   
 (所影响的行数为 4 行) 
 */   
------解决方案----------------------有事先写到这里   
 create table A(姓名 varchar(20), 编号 varchar(20)) 
 insert A se