How would you write an SQL query using joins, aggregations, subqueries, and window functions to extract meaningful business insights?