当前位置: 代码迷 >> Sql Server >> 求一复杂的条件排序语句,该怎么处理
  详细解决方案

求一复杂的条件排序语句,该怎么处理

热度:70   发布时间:2016-04-27 17:54:28.0
求一复杂的条件排序语句
表中如下三个关键字段
sender,receiver,sendtime
数据如下:
11   21   2007-1-2
11   22   2007-1-3
21   11   2007-1-3
11   21   2007-1-4
22   11   2007-1-2
12   23   2007-1-2

排序后,希望结果如下:
11   21   2007-1-2
21   11   2007-1-3
11   21   2007-1-4

22   11   2007-1-2
11   22   2007-1-3

12   23   2007-1-2

万分感谢~

------解决方案--------------------
create table test_a(sender int,receiver int,sendtime datetime)
insert into test_a
select 11,21, '2007-1-2 '
union all select 11,22, '2007-1-3 '
union all select 21,11, '2007-1-3 '
union all select 11,21, '2007-1-4 '
union all select 22,11, '2007-1-2 '
union all select 12,23, '2007-1-2 '

select * from test_a
order by sender+receiver,sendtime
  相关解决方案