表 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
-----------------------
谢谢。。
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
-----------------------
谢谢。。
参考一下这个贴子的提问方式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)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
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