cagartner
12/19/2016 - 5:30 PM

gistfile1.txt

select id from task as t
where t.id IN ( select task_id
from `task_history`
where (SELECT MAX(changed_at) as changed FROM task_history where task_id = t.id) <= UNIX_TIMESTAMP(STR_TO_DATE(DATE_ADD( CURDATE(), INTERVAL -2 MONTH), '%Y-%m-%d'))
and status_id <> 6
order by task_id DESC )