SQL 根据两个可互换的字段排序 table

SQL Sorting table based on two interchangeable fields

我想按进行通信的顺序对具有 3 列(时间、来源、收件人)的 table 进行排序。如果源和接收者正在一起交谈,那么它会按时间列出他们。目标是查看按 time.An 排序的相似人之间发生的交流,例如:

time|source|recipient

1   paul    amy
2   amy     paul
3   amy     paul
5   paul    jane
8   amy     paul
9   jane    paul
10  paul    amy
11  paul    jane

最终结果会是这样

1   paul    amy
2   amy     paul
3   amy     paul
8   amy     paul
10  paul    amy
5   paul    jane
9   jane    paul
11  paul    jane

你的问题有点含糊。我有根据的猜测是你想要这个:

SELECT *
FROM   tbl
ORDER  BY (GREATEST(source, recipient), LEAST(source, recipient), "time";

The manual about GREATEST and LEAST.