数据表:
Id      Type
1       A
2       B
3       C
4       A
5       B
6       C
7       A
8       B
9       C如果得到以下结果
7       A
8       B
9       C
4       A
5       B
6       C
1       A
2       B
3       C谢谢!

解决方案 »

  1.   

    select
        a.*
    from
        tname a
    order by
        (select count(*) from tname where Type=a.Type and Id<=a.Id) desc,Id
      

  2.   


    select
        a.*
    from
        tname a
    order by
        (select count(*) from tname where Type=a.Type and Id>=a.Id) ,Id
    可以不用倒序的,查找大於等於的即可。
      

  3.   

    declare @a table
    (
    id int,
    type char(1)
    )
    insert into @a
    select 1,'A' union all
    select 2,'B' union all
    select 3,'C' union all
    select 4,'A' union all
    select 5,'B' union all
    select 6,'C' union all
    select 7,'A' union all
    select 8,'B' union all
    select 9,'C'select *
    from @a a
    order by (select count(1) from @a where id<a.id and type=a.type)desc,id
      

  4.   

    玩了会儿Google Earth,被挤到那么后面去了^^;
      

  5.   

    谢谢谢谢!俺要继续努力啊!!~~~~~>_<~~~~~