表 tab_1 求sql 语句 能实现下面排序
id   order_1   order_2
----------------------
1                1
2        1       0
3        1       0
4        1       0
5                2
6        5       0
7        5       0
8                3
9        8       0
10       8       0
-----------------------
谢谢。。

解决方案 »

  1.   

    ??SELECT * FROM TB ORDER BY id,isnull(order_1,-999999),order_2 DESC
      

  2.   

    select * from tab_1 order by id 
      

  3.   

    建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  4.   

    打个比方 我现在添加一条数据,其id 则为“11,1,0”,那么通过这条排序语句就排在id为4的后面。
      

  5.   

    现在不是要插条新数据么,例如“11,1,0” 通过这样的sql语句来让他排到第五条。
      

  6.   

    楼主啊。 看一下别人是如何提问的吧。否则大家难理解你的需求。建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
     参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
     
      

  7.   

    --> 测试数据:#
    if object_id('tempdb.dbo.#') is not null drop table #
    create table #(id int, order_1 int, order_2 int)
    insert into #
    select 1, null, 1 union all
    select 2, 1, 0 union all
    select 3, 1, 0 union all
    select 4, 1, 0 union all
    select 5, null, 2 union all
    select 6, 5, 0 union all
    select 7, 5, 0 union all
    select 8, null, 3 union all
    select 9, 8, 0 union all
    select 10, 8, 0 union all
    select 11, 1, 0select * from # t order by isnull(order_1, (select top 1 order_1 from # where id>t.id order by id)), id