Select *,(Select count(*) from 表 where shift = a.shift and wno <= a.wno) as [order]
from 表 a

解决方案 »

  1.   

    Select *,(select sum(1) from 表 where shift=tem.shift and wno<=tem.wno) [order] from 表 tem
      

  2.   

    Select *,(Select count(*) from 表 where shift = a.shift and wno <= a.wno) as [order]
    from 表 a
      

  3.   

    各位已答对了,但我的问题依然没有解决,其实问题应该是这样的:
    A01
    A01
    A01
    A01
    A01
    R01  
    R01  
    R01  
    R01 
    只有一列:想得到
             A01  1
    A01  2
    A01  3
    A01  4
    A01  5
    R01  1
    R01  2
    R01  3
    R01 4谢谢啦!
      

  4.   

    只有一个字段,那就再加一个字段再说。
    Select f1,identity(int,1,1) as iid into #tmp from 表
    Select f1,(Select sum(1) from #tmp where f1 = a.f1 and iid<= a.iid) as id from #tmp a
      

  5.   

    你的问题跟我问的一样,在不允许用临时表等条件下,直接用一个SQL语句添加一个递增列,我问了很多人都不知道该如何写。:)
      

  6.   

    Select shift,(select sum(1) from 表 where shift=tem.shift and wno<=tem.wno) [order] from 表 tem
    ??