Skip to content

Instantly share code, notes, and snippets.

@JasonTrue
Created February 28, 2020 03:38
Show Gist options
  • Save JasonTrue/2cc06bf094692c13480f1056b82d0d32 to your computer and use it in GitHub Desktop.
Save JasonTrue/2cc06bf094692c13480f1056b82d0d32 to your computer and use it in GitHub Desktop.
most_recent_notifications_older_than some date
select v.name, max(n.inserted_at)
from variables v
left join notifications n on v.id = n.variable_id
where tenant_id = 2
group by v.name
having max(n.inserted_at) < '2020-02-28 12:25:07.000000'
or max(n.inserted_at) is null --disjunction clause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment