You are analyzing a Trust & Safety product in BigQuery. Assume 'today' is 2025-09-01 (UTC). Define precise metrics and write SQL to compute them, being explicit about edge cases.
Schema (invented):
Sample rows: users +----------+---------+---------------------+ | user_id | country | signup_time | +----------+---------+---------------------+ | 1 | US | 2025-01-05 10:00:00 | | 2 | IN | 2025-07-12 08:00:00 | | 3 | US | 2025-08-20 12:00:00 | | 4 | BR | 2025-06-01 09:30:00 | +----------+---------+---------------------+
events +----------+---------------------+-------------+ | user_id | event_time | event_type | +----------+---------------------+-------------+ | 1 | 2025-08-29 02:00:00 | post | | 1 | 2025-08-30 03:00:00 | login | | 2 | 2025-08-28 11:00:00 | comment | | 3 | 2025-08-27 16:00:00 | message | | 4 | 2025-07-15 18:00:00 | post | +----------+---------------------+-------------+
content +------------+-------------------+---------------------+---------+ | content_id | uploader_user_id | created_time | country | +------------+-------------------+---------------------+---------+ | 100 | 1 | 2025-08-28 05:00:00 | US | | 101 | 2 | 2025-08-26 10:00:00 | IN | | 102 | 3 | 2025-08-31 01:00:00 | US | | 103 | 4 | 2025-07-01 06:00:00 | BR | +------------+-------------------+---------------------+---------+
moderation_decisions +------------+-----------+---------------------+ | content_id | decision | decision_time | +------------+-----------+---------------------+ | 100 | violation | 2025-08-31 07:00:00 | | 100 | clean | 2025-09-02 01:00:00 | | 101 | clean | 2025-08-27 12:00:00 | | 102 | violation | 2025-09-01 10:00:00 | | 103 | violation | 2025-08-10 09:00:00 | +------------+-----------+---------------------+
auto_flags +------------+---------------------+----------+ | content_id | flag_time | rule_id | +------------+---------------------+----------+ | 100 | 2025-08-31 06:30:00 | R1 | | 101 | 2025-08-26 10:30:00 | R2 | | 102 | 2025-09-01 09:00:00 | R1 | | 102 | 2025-09-01 09:05:00 | R1 | +------------+---------------------+----------+
Task A — 7-day Confirmed Violation Rate per 1,000 Active Users by country:
Task B — 28-day Auto-Flag Precision by rule_id:
Edge cases to handle explicitly in your SQL: time zones (assume all timestamps UTC), late-arriving decisions (outside windows are ignored), users with no country (coalesce with content.country), and zero-division (precision should be 0.0 if flags=0).