cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
SQL Alerts are very handy to keep track of any critical metrics. Oftentimes it makes most sense to do a relative comparison of your data. For instance, "alert me if my metric dropped between yesterday and today." The below SQL code is an example of how you can do that!
with
  current_value as (
    select
      count(*) as val
    from
      users
    where
      [created_at:date]=[getdate():date]
  )
  , past_value as (
    select
      count(*) as val
    from
      users
    where
      [created_at:date]=[getdate() - Interval '1 day':date]
  )
select
  current_value.val - past_value.val as difference
from
  current_value
  , past_value
Now, set your alert to trigger every time the output is less than 0! Voila - a relative comparison of your metrics 🙂
Rate this article:
Version history
Last update:
‎03-02-2023 09:34 AM
Updated by:
Contributors