Optimize windowed aggregations