Aggregate data in time interval specified by table2 from very large table1 Suppose I have the following 2 tables: