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
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: jdbc怎么配置多个mysql节点