Optimize a slow-running SQL query that aggregates millions of customer interaction events across multiple sharded tables.
Write a PostgreSQL query that processes the January 2025 event data from both shards, associates events with known customers, and returns only customer and event-type combinations with at least two qualifying events.
Output
- One row per customer and event type
- Columns:
customer_id, customer_name, event_type, event_count, and total_duration_seconds
- Include only January events for known customers with at least two events
- Order by
event_count descending, then customer_id ascending and event_type ascending