把相应的recNO值根本不同类别增量加1
这句是什么意思?按你给出的数据,更新后的结果应该是什么?

解决方案 »

  1.   

    select IDENTITY(int,1,1) as id,*
    into #t from 表
    order by Nametruncate table 表insert 表
    select Name,recNo=(select min(recNo) from #t where name=a.name)+(select count(*) from #t where name=a.name and id<=a.id)-1
    from #t a
    order by Name,iddrop table #t猜呗,错了不管哈,哈哈,哈哈哈......
      

  2.   

    结果应该是:Name        recNo
    -----------------
    a            1
    a            2
    a            3
    b            2 
    b            3
    c            4
    c            5
    c            6
    c            7
    d            4
    e            5
    e            6
    f            6
    f            7
    g            7
    g            8
    g            9不过错了不管哈,哈哈,哈哈哈......
      

  3.   

    select Name,(select count(distinct Name) from t where Name<=a.Name) recNo
    from t a order by Name
      

  4.   

    to: zjcxc(邹建不好意思我没说清楚:
    原表中RECNO字段为空,刚才举的例子是返回结果!
      

  5.   

    select IDENTITY(int, 1,1) AS ID_Num ,* into #t from ( select distinct name  from table1) a
    select * from #t
    update table1 set recNo=#t.ID_Num from table1 inner join #t on #t.name=table1.name
      

  6.   


    真乃牛人也!!!不过当字段name为其它类型时(需要自己加order by)时怎么办呢?加在哪里??谢!
      

  7.   

    跟类型没关系,再贴一遍:
    select Name,(select count(distinct Name) from t where Name<=a.Name) recNo
    from t a order by Name
      

  8.   

    to:你的方法不行.
    因为原始表中的recno为空.
      

  9.   

    TO:风云
    我的原始表中RECNO字段是空的,你的结果不对啊~~~~~~~
      

  10.   

    update t
    set recNo=(select count(distinct Name) from t where Name<=a.Name)pbsql(风云) 都送你到家门口了,还要问“我用左脚还是右脚跨进去”?哈,哈哈,哈哈哈......
      

  11.   

    不是太懂SQL啊,~~~
    还是报错,提示:列前缀'a'与查询中所用的表名或别名不匹配
      

  12.   

    update t
    set recNo=(select count(distinct Name) from t a where a.Name<=t.Name)