MySQL以不同的排序顺序对多列进行排序 [英] MySQL sorting multiple columns with different sort order

查看:330
本文介绍了MySQL以不同的排序顺序对多列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中有三个字段,其数据类型分别为dateintbigint.

I have a table in which I have three fields with data type date, int and bigint.

我想使用所有这三列对我的选择查询进行排序.我想按降序对它们进行排序.例如:

I want to sort my select query using all these three columns. I want to sort them all in descending order. For example:

Select * From mytbl 
order by date desc,intnum desc, bigintnum desc;

我是否有可能从所有三列的最大值开始获得结果. 例如最新日期,最高整数和最高bigintnum.

Is it possible that i could get a result starting from max of all three columns. like latest date, highest intnum and higest bigintnum.

推荐答案

查询所得到的是max date,然后是max datemax intnum,然后是max date

What your query does is get the max date, followed by the max intnum of the max date followed by the max bigintnum of the max intnum of the max date

换句话说,您的查询不会返回所有三列的最大值

In other words, your query would not return the maximum value of all three columns

它先按日期排序,然后按整数顺序,然后按bigintnum顺序排列 结果将是这样

It orders by the date first, then the intnum, then the bigintnum The results would be something like this

2011-07-20    12    14
2011-07-20    12    13
2011-07-20    11    16
2011-07-20    10    12
2011-07-19    20    15
2011-07-18    60    30
2011-07-18    50    14

这篇关于MySQL以不同的排序顺序对多列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆