0
I have a query that returns the last accesses of the users in the system. I would like to know how I could treat to return only those dates that are longer than 15 days.
This is the consultation:
SELECT u.id, concat(u.firstname,' ',u.lastname) as nome,from_unixtime(MAX(l.time)),
DATEDIFF(now(),from_unixtime(MAX(l.time))) as Dias
FROM mdl_role_assignments rs
INNER JOIN mdl_user u ON u.id=rs.userid
INNER JOIN mdl_context e ON rs.contextid=e.id
INNER JOIN mdl_log l ON l.userid=u.id
WHERE e.contextlevel=50 AND rs.roleid=5 AND e.instanceid=2174 AND l.course=e.instanceid
GROUP BY u.id, u.firstname,u.lastname
order by Dias desc
The main table for this operation is the mdl_log which stores these records with iduser and Course (which I used to filter the course id=2174 in e. instanceid)
I already tried to pass the function MAX() in Where, I tried to pass that same SELECT in WHERE comparing the return with any date... without success.
if you only want the last 15 days, it would not be enough to just compare the date using
(CURDATE() - INTERVAL 15 DAY)
?– Ricardo Pontual
The problem is that the table keeps all access dates, why I passed the l.time field within max()
– GOliveira
Remembering that if I have to catch the last access and that it has been more than 15 days
– GOliveira