I have these snowflake sql queries and I also attached a sample of the table:
--- (4) MULTIPLE ACCOUNTS HEAVY ABUSE DATASET ---
CREATE OR REPLACE TABLE playground.signup_multiple_accounts_for_abuse_rate AS (
SELECT
t1.sitename,
t1.sessionid,
t1.transsource,
t1._transdate,
t1.transtime,
LOWER(t1.decisionansweredtomerchant) AS decision,
t1.customerid,
t1.useremail,
t1.firstdecisionrule,
t2.evr:num_of_emails_in_site."connected"."14_days".emails_first_seen::real AS num_of_emails_in_site_14d,
t2.evr:num_of_emails_in_site."connected"."90_days".emails_first_seen::real AS num_of_emails_in_site_90d,
t2.evr:num_of_emails_in_site."connected"."365_days".emails_first_seen::real AS num_of_emails_in_site_365d,
t2.evr:num_of_emails_in_site."connected"."inf_days".emails_first_seen::real AS num_of_emails_in_site_inf,
t1.emaildomain,
t1.connectionattribute:connectionType AS connection_type,
t1.maxmindcountry,
t1.maxmindispname,
t1.emailhightype
FROM
touchpoints t1
JOIN
touchpoints_evr t2 ON t1.requestuniqueid = t2.requestuniqueid
WHERE
t1.transsource = 'AccountSignup'
AND t1._transdate > current_date - 90
AND LOWER(t1.sitename) IN ('upworktalentmarketplace', 'rbi burgerking uk', 'rbi burgerking us', 'gopuff', 'rbi timhortons ca', 'nordstrom', 'seagm', 'gopuff')
AND LOWER(t1.decisionansweredtomerchant) <> 'not_reviewed'
);
--- TREND ---
SELECT
_transdate,
sitename,
COUNT(*) AS total_cnt,
COUNT_IF(num_of_emails_in_site_14d > 5) AS heavy_abuse_14d_cnt,
ROUND(100 * DIV0(heavy_abuse_14d_cnt, total_cnt), 2) AS heavy_abuse_14d_rate
FROM
playground.signup_multiple_accounts_for_abuse_rate
GROUP BY
1, 2
ORDER BY
1, 2;
Sample output:
TRANSDATESITENAMETOTALCNTHEAVY_ABUSE_14D_CNTHEAVY_ABUSE_14D_RATE2025-03-13RBI BurgerKing UK3074250.812025-03-13RBI BurgerKing US22096360.162025-03-13RBI TimHortons CA1376830.022025-03-13SEAGM40141202.992025-03-13UpworkTalentMarketplace3895018394.72
Request:
I want you to modify the queries so:
add additional column that indicates whether or not a spike of HEAVY_ABUSE_14D_RATE occured. the logic should rely on comparing the rate of a given day to a baseline of the same SITENAME to identify anomalies.
In additional columns collect all the unique values seen in the datapoints: emaildomain, connection_type, emailhightype, ip_c_class.
now go back to the original table signup_multiple_accounts_for_abuse_rate, per site filter the data to only the rows matching values in emaildomain, connection_type, emailhightype, ip_c_class where there is a spike in HEAVY_ABUSE_14D_RATE