How would you handle query optimization for complex analytics workloads on cloud data warehouses like Snowflake or BigQuery?
Using the supplied PostgreSQL tables, write a query that demonstrates an efficient analytics pattern over a fixed three-month period. Include only completed encounters within the period, preserve facilities with no activity, and produce monthly metrics with a rolling three-month charge total.
Output
- One row per facility and month from January through March 2025.
- Columns:
facility_name, month_start, encounter_count, total_units, total_charges, and rolling_three_month_charges.
- Include facilities with no qualifying encounters as zero-valued rows, ordered by facility name and month.