mysql中如何按照日期排序

九三
2477
2020-12-17 09:19:02
欄目: 云計(jì)算

mysql中如何按照日期排序

mysql中實(shí)現(xiàn)按日期排序的方法

表結(jié)構(gòu)如下:

+---+------------+

|id | addtime |

+---+------------+

| 5 |2020-03-06 |

+---+------------+

| 6 |2020-03-21 |

+---+------------+

| 7 |2020-03-29 |

+---+------------+

1.首先,在表中利用DATE_FORMAT函數(shù)對(duì)表的日期進(jìn)行格式化;

select * from browser_history where date_format(addtime,'%Y-%m-%d') = '2019-03-06';

2.表中的日期格式化好后,執(zhí)行以下命令即可對(duì)日期進(jìn)行排序;

select DATE_FORMAT(addtime,"%Y-%m-%d") as ndate from browser_history where uid = 822 group by ndate

0