Walk me through a complex SQL query you wrote recently. What joins and window functions did you use to optimize its performance?