我有 1 个表,有 6 列,都是 tinyint 和 1 位数字。 我需要一个查询来返回每列中按降序排序(排序)的数据。
例子:
col1 col2 col3
1 2 5
1 7 3
2 3 7
预期结果:
2 7 7
1 3 5
1 2 3
我尝试按 col1, col2 DESC 排序,但它只影响第一列(可能是因为它来自同一个表?) 谢谢, 丹尼
最佳答案
也许是这样的:
select col1, col2, col3
from
( select row_number() r, col1 from mytab order by col1 desc ) a,
( select row_number() r, col2 from mytab order by col2 desc ) b,
( select row_number() r, col3 from mytab order by col3 desc ) c
where a.r = b.r
and a.r = c.r
关于mysql多列排序顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18988147/