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;
so, is there any simpler way?