Skip to content

Instantly share code, notes, and snippets.

@JRGGRoberto
Last active December 3, 2015 10:33
Show Gist options
  • Save JRGGRoberto/b0e261381175bea69e73 to your computer and use it in GitHub Desktop.
Save JRGGRoberto/b0e261381175bea69e73 to your computer and use it in GitHub Desktop.
select
t.ticketid, t.st, greatest(t.modifiedtime, ifnull(a.dt, t.modifiedtime), ifnull(c.dt,t.modifiedtime)) dt,
t.tec, t.title,
TIMESTAMPDIFF( day, greatest(t.modifiedtime, ifnull(a.dt, t.modifiedtime), ifnull(c.dt,t.modifiedtime)), NOW() ) diasabando
from
tksabc2 t
left join atividades a on a.tk = t.ticketid
left join comments c on c.related_to = t.ticketid
group by 1, 2
order by 1, 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment