求一复杂的条件排序语句

fk424 2007-03-16 02:08:30
表中如下三个关键字段
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

万分感谢~
...全文
225 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fk424 2007-03-16
  • 打赏
  • 举报
回复
我的意思就是sender和receiver可能是互为发送和接收方的!我想先分组,再每组中再按照时间顺序排列!
wangdehao 2007-03-16
  • 打赏
  • 举报
回复
我晕,我看一大顿还没看出规律来呢
gahade 2007-03-16
  • 打赏
  • 举报
回复
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

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧