SQL Alert - Tell Me If A Value Dropped Since Yesterday
Summary: intapiuser is seeking help on setting up an SQL alert to notify when a specific value has decreased compared to the previous day.
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_valueNow, set your alert to trigger every time the output is less than 0! Voila - a relative comparison of your metrics 🙂

0 comments