Start by breaking the problem into three independent feature computations using CTEs, each with its own time-window logic and aggregation. Then join the flags back to the user dimension, apply the weighted risk score threshold, and filter to the past 7 days. Emphasize correctness of window functions and clear assumptions about schema and weights.
Pro tip: Explicitly state your assumptions about the schema (e.g., timestamps, country fields, acceptance status) and the risk weights, and mention that you would validate the query on a small sample before running it at scale. This shows production maturity and avoids silent errors.
Restate the table structures and precisely define each flag in SQL terms, including time windows and thresholds. Confirm the risk weights and the 7-day lookback window.
Use a self-join or window function to find users with 3+ distinct countries within any rolling 24-hour window in the past 7 days.
For messaging, join messages to users and count distinct recipients within 5 minutes of account creation. For friend requests, aggregate requests and acceptances per user, then flag those with 20+ requests and acceptance rate < 10%.
Join the three flag CTEs on user_id, compute the weighted risk score using the given weights, and filter to users with score >= 0.5.
Write the final SQL with clear CTEs, ensure only users from the past 7 days are included, and mention potential performance improvements like indexing or partitioning.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.