一个成绩表,我想在数据库里加个按成绩排序的字段,只能按排序要求打开记录集,一条条更新?有没有更好的办法

解决方案 »

  1.   

    描述不够详细,
    你说的要按照派需要打开纪录集更新应该指的是前段form操作控制。
    依据成绩排序必须要考虑成绩相同怎么办,
    所以需要组合多个栏位排序
      

  2.   


    --創建測試表
    create table table1
    (
    [id] int identity primary key not null, --表主鍵
    [source] int not null, --成績
    [ord] int   --排序字段
    )
    insert into table1(source) values(91)
    insert into table1(source) values(92)
    insert into table1(source) values(99)
    insert into table1(source) values(83)
    insert into table1(source) values(85)--更新測試,此測試語句可寫入存儲過程或直接在查詢分析器中使用,可滿足LZ需求
    select identity(int,1,1) as ord, cast([id] as int) as id   into #a  from table1 order by source desc
    update table1 set ord=b.ord from #a b where table1.id=b.id--查看測試結果,並刪除測試表
    select * from table1
    drop table #a
    drop table table1--------------------------------------
    id      source  ord
    1 91 3
    2 92 2
    3 99 1
    4 83 5
    5 85 4