gpt4 book ai didi

mysql - 仅在 MySQL 中返回最近 3 个月的记录

转载 作者:IT老高 更新时间:2023-10-28 23:49:13 26 4
gpt4 key购买 nike

我有一个带有时间戳字段的表。如何获取最近 3 个月的数据?

特别是,三月是我当前的月份,比方说,03/2012。我只需要返回三月、二月和一月的记录。

最佳答案

今天前 3 个月:

select * from table where timestamp >= now()-interval 3 month;

从月初开始:

select * from table where timestamp >= last_day(now()) + interval 1 day - interval 3 month;

关于mysql - 仅在 MySQL 中返回最近 3 个月的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15397015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com