同时按两列排序



我正在为呼叫中心创建报告。报表中的扩展可以是源或目标。我需要同时通过 src 和 dst 订购报告。因此,所有在分机中最低号码发起或终止的呼叫都将首先列出,而不是下一个号码等。等。。。以下查询将按顺序为 src 提供所有调用,然后按顺序从 dst 提供所有调用,但我无法弄清楚如何实现我的目标。感谢您的任何帮助!

select src, dst, calldate, disposition from cdr where calldate > '2020-11-07' and calldate < '2020-11-12' 
and disposition = 'answered'
and ((src in ('2003', '2001', '2002', '2004', '2099', '2053', '2051')) 
or (dst in ('2003', '2001', '2002', '2004', '2099', '2053', '2051'))) order by src, dst;

你似乎想要:

order by least(src, dst), src, dst

这按srcdest之间的最小值对行进行排序;通过取最小的src,然后取最小的dst来打破连接。

最新更新