I have a query that returns me the last accesses of the users in the system. I would like to know how I could handle it to return only dates that were longer than 15 days.
The query is this:
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 that stores those records next to the iduser and course (which I used to filter the course of id = 2174 in e.instanceid )
I have tried to pass the MAX () function in the where, I tried to pass that same SELECT into WHERE by comparing the return with any date ... without success.