Find Max() updated time for a group of users
0
votes
3
answers
230
views
Database is MariaDB 10.3.25
I have 2 columns that are relevant:
UserID and LastUpdate
UserID consists of user@domain
LastUpdate is a date field.
Here is my issue - I have the current query:
select a.UserID,
substring_index(a.UserID, '@', -1),
max(a.lastupdate)
from MyTable a
group by a.UserID
having max(a.lastupdate) < '2020-03-31'
This shows all the Users that haven't updated in just over a year and the domain. However there is the following scenario that I want to account for:
UserID LastUpdate
A@A.com 2020-08-16
B@A.com 2019-05-16
C@A.com 2021-05-05
With the current query, B@A.com will be captured, and therefore domain A.com will be captured as not in use, but the user C@A.com is still active - I want to do a Max(a.lastupdate) but have it grouped by
substring_index(a.UserID, '@', -1)
but also spit out all the users for that domain.
I'm sure the answer is starring me in the face...
Asked by TheDemonLord
(193 rep)
May 4, 2021, 10:53 PM
Last activity: May 5, 2021, 04:54 PM
Last activity: May 5, 2021, 04:54 PM