mysql中实现按日期排序的方法
表结构以下:
+---+------------+
|id | addtime |
+---+------------+
| 5 |2020-03-06 |
+---+------------+
| 6 |2020-03⑵1 |
+---+------------+
| 7 |2020-03⑵9 |
+---+------------+
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
本文来源:https://www.yuntue.com/post/58287.html | 云服务器网,转载请注明出处!