1次中mysql 3不同的排序 [英] mysql 3 different sort in 1time
本文介绍了1次中mysql 3不同的排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的桌子:
id | is_quick_plus | is_quick | top_date | date
----|---------------|----------|------------|------------
1 | 1 | 0 | 2017-11-29 | 2017-11-01
2 | 0 | 1 | NULL | 2017-11-01
3 | 1 | 0 | NULL | 2017-11-02
4 | 0 | 1 | 2017-11-28 | 2017-11-01
5 | 0 | 0 | NULL | 2017-11-03
当前排序是(1,4,2,3,5)
The current sort is (1,4,2,3,5)
1和4的top_date其他按日期排序
1 and 4 have top_date other sort by date
当我排序时
is_quick_plus DESC, is_quick DESC, top_date DESC, date DESC
一行没有top_date上升,因为它具有is_quick_plus但已过期..并应按日期排序..
one row has no top_date going up because it has is_quick_plus but has expired .. and should sort by date ..
我只想先按is_quick_plus和top_date,然后按is_quick和top_date,再按日期...在1个查询中排序
I just to first sort by is_quick_plus and top_date, then is_quick and top_date, then by date ... in 1 query
推荐答案
我通过在select末尾使用group BY解决了该问题
I solved it by using a group BY in the ending of the select
这篇关于1次中mysql 3不同的排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文