日期:2014-05-18  浏览次数:20544 次

求一复杂的条件排序语句
表中如下三个关键字段
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