时间:2022-12-06 01:18
通过在数据表使用以下命令实现的排序
1.单列排序
SELECT * FROM test1 ORDER BY date_time
2.多列排序
SELECT * FROM test1 ORDER BY `status`, date_time DESC
3.自定义排序
SELECT * FROM test1 ORDER BY FIELD(`status`, 3, 2, 4, 1, 5), date_time DESC
4.条件排序
SELECT * FROM test1 ORDER BY date_time < NOW(), IF(date_time < NOW(), 0, date_time), date_time DESC