Set datasource based on time range

Hi, how can I automatically control the datasource used based on the timerange used, i.e flipping seamlessly to a downsampled data set when the selected time range is longer or older than a defined threshold?

Looking at doing this with InfluxDBv3 SQL but am certainly presuming this should be able to be datasource agnostic.