create table #t2
(
 k int ,
 j char
)
insert into #t2
select 1,'0'
union
select 2,'0'
union
select 3,'0'
union
select 1,''
union
select 2,''
union
select 3,''
select * from #t2如何实现结果如下呢?
1 1
1 2
2 1
2 2
3 1
3 2
也就是说第一个数字一样的时候从一开始排,
例如在有一个3的话,结果是这样的
3 3

解决方案 »

  1.   

    select * from order by k,cast(j as int)
      

  2.   

    create table #t2
    (
     k int,
     j char
    )insert into #t2
    select 1,'0' union
    select 2,'0' union
    select 3,'0' union
    select 1,'' union
    select 2,'' union
    select 3,''
    begin trandeclare @i int
    select @i=0
    update #t2 set j=@i,@i=@i+1
    update #t2 set j=(select count(*) from #t2 where k=a.k and j <=a.j) from #t2 aselect * from #t2
    rollback trandrop table #t2
      

  3.   

    本人的操作系统是win2000装了iis5.0和sql,在我点开始-程序-sql时,
    sql后面为“空”,我双击程序里的sql,出现了Error: Unable to read footer file.有谁知道这个是什么错误呢?
      

  4.   

    借用楼上的临时表
    create table #t2
    (
     k int,
     j char
    )insert into #t2
    select 1,'0' union
    select 2,'0' union
    select 3,'0' union
    select 1,'' union
    select 2,'' union
    select 3,''select *,id=identity(int,1,1) into #t1 from #t2select k,j=(select count(1) from #t1 where k=a.k and id<=a.id)
    from #t1 a