我有一个sql查询,结果如下表所示。
+-------+----------+---------------------+--------------------------------------+
| tp_id | tp_title | tp_completed_at | uto_order |
+-------+----------+---------------------+--------------------------------------+
| 69033 | task3 | 2017-03-17 08:15:38 | 3401893506280706400000000.0000000000 |
| 69022 | post 1 | 2017-03-15 10:24:03 | 1122274146401882300000000.0000000000 |
| 69032 | task4 | 2017-03-17 08:15:35 | 810531327956915000000000.0000000000 |
| 68998 | final | 2017-03-13 14:23:18 | 498788509511947700000000.0000000000 |
| 68978 | app4 | 2017-03-13 14:05:39 | 221683782005310100000000.0000000000 |
| 68850 | 7 | 2017-02-24 07:58:38 | 12974633789062503000000.0000000000 |
| 68845 | 6 | 2017-02-24 07:54:14 | 5766503906250001000000.0000000000 |
+-------+----------+---------------------+--------------------------------------+
我想单独根据tp_completed_at
和uto_order
对结果进行排序。我的意思是,首先查询应该基于tp_completed_at
对结果进行排序,然后再次根据uto_order
对tp_completed_at
中具有相同日期的记录(不包括时间戳)对整个数据进行排序,例如,任务3和任务4在基于tp_completed_at
进行排序后将彼此相邻,如下所示
+-------+----------+---------------------+--------------------------------------+
| tp_id | tp_title | tp_completed_at | uto_order |
+-------+----------+---------------------+--------------------------------------+
| 68845 | 6 | 2017-02-24 07:54:14 | 5766503906250001000000.0000000000 |
| 68850 | 7 | 2017-02-24 07:58:38 | 12974633789062503000000.0000000000 |
| 68978 | app4 | 2017-03-13 14:05:39 | 221683782005310100000000.0000000000 |
| 68998 | final | 2017-03-13 14:23:18 | 498788509511947700000000.0000000000 |
| 69022 | post 1 | 2017-03-15 10:24:03 | 1122274146401882300000000.0000000000 |
| 69032 | task4 | 2017-03-17 08:15:35 | 810531327956915000000000.0000000000 |
| 69033 | task3 | 2017-03-17 08:15:38 | 3401893506280706400000000.0000000000 |
+-------+----------+---------------------+--------------------------------------+
我想再次基于uto_order
,(任务4和任务3)基于uto_order,(app4和final)排序(6和7),因为所有这组任务都基于uto_order
同一天tp_completed_at
。怎么做?在此先感谢!!!
答案 0 :(得分:0)
使用:
ORDER BY CAST(tp_completed_at AS DATE) DESC, uto_order
答案 1 :(得分:0)
如果您要对date
的{{1}}部分进行排序,然后按tp_completed_at
进行排序,则可以使用MySQL的uto_order
函数,例如:
DATE_FORMAT