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