请教下  查询的出来的 数据要给他定义一个编号 如下 
No Bo Co 
 1 B2 C2 
 2 B8 C9
 3 B3 C3 
 4 B4 C3
查询出的结果给他编号第一条是给个编号1 第2条是2 依此类推

解决方案 »

  1.   


    select row_number()over(order by getdate()) as No,Bo,Co from tb
      

  2.   

    --> 测试数据:#TA
    if object_id('tempdb.dbo.#TA') is not null drop table #TA
    create table #TA([No] int,[Bo] varchar(2),[Co] varchar(2))
    insert #TA
    select 1,'B2','C2' union all
    select 2,'B8','C9' union all
    select 3,'B3','C3' union all
    select 4,'B4','C3'
    select *,ct=(select COUNT(1) from #TA where No<=a.No) from #TA aselect *,ct=(select COUNT(1) from #TA where Bo<=a.Bo) from #TA a
      

  3.   

    2005用1楼,2000用2楼.不过,你的结果最好是:No Bo Co 
     1 B2 C2 
     2 B3 C3 
     3 B4 C3
     4 B8 C9这样符合Bo或Co的排序.