How would you write complex joins, window functions, and aggregations to query internal portfolio databases?