Tariffs Query Optimization

I was wondering if anyone could help me optimize this query. I have a ‘tariffs’ table with a ‘rate’ field and tags including start hour, end hour, weekday, valid from and valid to. I need to join this with another table which has a ‘kWh’ field and multiply the kWh with the correct ‘rate’.

My query is below, it works okay for short windows but I need to be able to query data up to a year.

Is there anything I can change with the query to make it more efficient or do I need to change the way I am approaching this?