How does mysql get a record of N months (days) since the last update?

< table > < thead > < tr > < th > mysql > select * from mytable; < / th > < / tr > < / thead > < tbody > < tr > < td > id < / td > < td > userid < / td > < td > point < / td > < td > lastUpdate < / td > < / tr > < tr > < td > 1 < / td > < td > 1 < / td > < td > 10 < / td > < td > 2018-01-02 00:00:00 < / td > < / tr > < tr > < td > 2 < / td > < td > 1 < / td > < td > 10 < / td > < td > 2018-02-03 00:00:00 < / td > < / tr > < tr > < td > 3 < / td > < td > 1 < / td > < td > 10 < / td > < td > 2018-02-04 00:00:00 < / td > < / tr > < tr > < td > 4 < / td > < td > 1 < / td > < td > 10 < / td > < td > 2018-04-04 00:00:00 < / td > < / tr > < / tbody > < / table >

4 rows in set (0.00 sec)

for example,

within 3 months of the last update.

I try to use TIMESTAMPDIFF, if it is directly compared to the specified time, such as now ():
select * from mytable where TIMESTAMPDIFF (month,lastUpdate,now ()) < 3;

but if this time is to be obtained from the original table, such as the largest lastUpdate, here, I would like to use max, in a form similar to the following (of course, this must be an error):
select * from mytable where TIMESTAMPDIFF (month,lastUpdate,max (lastUpdate)) < 3;
(it will be easier if userid is added here)

how to use the aggregate function in TIMESTAMPDIFF, because the aggregate function needs to involve group by, especially if it is obtained by the max of sql_mode=only_full_group_by,.
if it is not sql_mode=only_full_group_by, it can be used directly

.

I think about it. This max (lastUpdate) can replace
select * from mytable where TIMESTAMPDIFF (month,lastUpdate, (select max (lastUpdate) from mytable)) < 3;

with a subquery.

so, is there any simpler way?

Mar.02,2021

make time difference, date > '2018-01-01'


SELECT * FROM table_1 a LEFT JOIN (
SELECT MAX (time) as tt FROM table_1
) b on 1
WHERE TIMESTAMPDIFF (MONTH,a.time,b.tt) < 3
so that you can see whether it can be done

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eac55e-47ea1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eac55e-47ea1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?