Advanced queries for historical data