select 姓名,sum(语文) as 语文,sum(数学) as 数学,sum(英语) as 英语 from 
(select 姓名,语文=(case when 课程名称=语文 then 成绩 else 0 end),
数学=(case when 课程名称=数学 then 成绩 else 0 end),
英语=(case when 课程名称=英语 then 成绩 else 0 end)) a
  group by 姓名

解决方案 »

  1.   

    declare @i int,@c varchar(10),
    declare cur_cur cursor for select * from table1
    delete from table1
    open cur_cur 
    fetch next from cur_cur into @c,@i
    while @@fetch_status=0 
     begin 
       while @i>0
         begin 
           insert into table1 select @c,1
           set @i=@i-1
         end
     end
    deallocate cur_cur
      

  2.   

    create table  #t (styl_no varchar(10),no int)
    declare @styl_no varchar(10),
                @no int,
               @i intset @i=1
    declare cu_1 cursor for
    SELECT  STYL_NO,MANU_QTY  FROM T_BRDL_FLOW_MANU
    WHERE FLOW_NO='B01' AND MANU_QTY>1
    ORDER BY  STYL_NO,SIZE_CD,SALE_NO
    open cu_1
    fetch cu_1 into @styl_no,@no
    while @@fetch_status=0
    begin
    while (@i<=@no )
    begin
     insert into #t select @styl_no,1
    set @i=@i+1
    end
                                    fetch cu_1 into @styl_no,@no
    set @i=1
    end
    close cu_1
    deallocate cu_1
    select * from #t
      

  3.   

    又错,唉 少了fetch next