mysql中实现按日期排序的方法
表结构如下:
+---+------------+
|id | addtime |
+---+------------+
| 5 |2020-03-06 |
+---+------------+
| 6 |2020-03-21 |
+---+------------+
| 7 |2020-03-29 |
+---+------------+
1.首先,在表中利用DATE_FORMAT函数对表的日期进行格式化;
select * from browser_history where date_format(addtime,'%Y-%m-%d') = '2019-03-06';
2.表中的日期格式化好后,执行以下命令即可对日期进行排序;
select DATE_FORMAT(addtime,"%Y-%m-%d") as ndate from browser_history where uid = 822 group by ndate