写一条SQL语句实现格式的转化,具体要根据你的表结构来,看看SQL的书,应该不难。我们以前做数据库项目时,经常有这种问题。

解决方案 »

  1.   

    select kemu from table1create table2 depandent on the select result
      

  2.   

    實現方法:
    如果課程不固定,則需建兩個表,一個表存儲課程名,另一個表存儲成績.
    1.Select * From 課程名,將課程名寫到列表視控件的標題欄上.並建一個數組存儲課程名
    2.Select 學號,姓名,課程,成績 From 成績表 Order By 學號
    設一變量 var學號=""
    開始循環讀記錄
    if (當前記錄學號!=var學號)
    {
    var學號=當前記錄學號;
    增加新Item,學號,姓名,
    與課程數組比對,確定在第幾個SubItem上顯示成績
    }
    else
    {
    與課程數組比對,確定在第幾個SubItem上顯示成績
    }
      

  3.   

    Which Database? SQL Server or Oracle or DB2?
      

  4.   

    SQL SERVER 7 有劳bob_yan(小保) 兄。
      

  5.   

    你好,我用存储过程给你实现。但是这个存储过程功能比较简单,只能处理课程是固定数目的情况。想要更简单的实现你的要求,建议你用PB的一些方法去做。你现看看下面的方法能不能实现你的要求。
    declare @xuehao1 char(3)
    declare @xuehao2 char(3)
    declare @xinming char(20)
    declare @kechen char(10)
    declare @chenji int
    declare @totalcore intselect @xuehao1=''
    select @xuehao2=''
    select @totalcore = 0
    select @kechen=''
    select @chenji=0create table #tmp xuehao char(3),xinming char(20) null,wangluo int null, yinyu int null,gaoshu int null, zongfen int null
    declare tmpcur cursor for
    select xuehao,xinming,kechen,chenji from table1 order by xuehao,kechen
    for read only
    open tmpcur
    fetch tmpcur into @xuehao1,@xinming,@kechen,@chenji
    while (@@fetch_status=0)
    begin
    if (@xuehao1<>@xuehao2)
    begin
    insert into #tmp(xuehao,xinming) values (@xuehao1,@xinming)
    select @xuehao2=@xuehao1
    end
    if (@kechen='wangluo')
    update #tmp set wangluo=@chenji where xuehao = @xuehao1
    if (@kechen='yinyu')
    update #tmp set yinyu=@chenji where xuehao = @xuehao1
    if (@kechen='gaoshu')
    update #tmp set gaoshu=@chenji where xuehao = @xuehao1
    fetch tmpcur into @xuehao,@xinming,@kechen,@chenji
    end
    close tmpcur
    deallocate tmpcur
    select *,wangluo+yinyu+gaoshu zongfen from #tmp
      

  6.   

    Sorry,刚才没有检查,中间表#tmp中的zonfen字段应该不要。
      

  7.   

    bob_yan(小保) 兄您好 谢谢您的回答。
     
      PB里的确有一种CROSSTAB风格的数据窗口可以很容易的做出该报表, 但是CROSSTAB有个BUG 就是在数据量大时会导致电脑死机。(只能重新启动) 
     
      VC的确是一种很强的工具。 PB 本身就是 VC 写出来的。 既然PB 都做出来了。 VC 因更不在话下啊。 bob_yan(小保) 兄 能不能找找您认识的VC高手们说说。     
      

  8.   

    你好,如果你想要一个能灵活处理课程的方法的话,比如动态适应课程数目不同的情况,就比较复杂一些,VC也没有什么好的工具来做,只能具体情况具体分析。如果你那边的课程的数目是固定的话,用我的方法就可以了。
    其实PB做报表比VC好很多,有会,应该可以更方便地找到方法。
      

  9.   

    上面Frank_Xu的方法应该可以解决你的问题。你是不是要用SQL实现Frank_Xu的方法?