Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to sort a table having 3 columns (time, source , recipient) by the order by which communication is being made. If the source and recipient are conversing together then it will list them by the time. The goal is to see the communication happening between similar people ordered by time.An example is as:

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

the end result would be like

1   paul    amy
2   amy     paul
3   amy     paul
8   amy     paul
10  paul    amy
5   paul    jane
9   jane    paul
11  paul    jane
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
120 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your question is a bit vague. My educated guess is you want this:

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

The manual about GREATEST and LEAST.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...