基于两个可互换字段的 SQL 排序表

编程入门 行业动态 更新时间:2024-10-28 10:25:59
本文介绍了基于两个可互换字段的 SQL 排序表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

最终结果是这样的

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

推荐答案

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

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";

关于GREATEST 和 LEAST.

更多推荐

基于两个可互换字段的 SQL 排序表

本文发布于:2023-10-07 20:07:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   两个   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!