Tag History Binding or Named Query

We have SQL Server with monthly partitions logging analog every 5 seconds. The QA user would like to select any time range and find out the percentage of temperature above the setpoint during the hot rinse is on. I am trying to use Tag History Binding or Named Query. But it seems I can't use conditions in the expression and if I use Named Query, I will have to union an unknown number of tables.

The logic is
if({Water_Temp_Fahrenheit} > {Water_Temp_Setpoint} && ({Hot_Water_Rinse} = 1 || {Hot_Water_Rinse} = 1), true, false)

Should I use Tag History Binding Wide/Tall/Calculations PointCount/AsStored? Or is there a better way to do this?

This is one of those situations that is trivial to solve when using transaction groups (or scripts) to store rows instead of using tag history (which is columnar).

Consider scripting a continuous analysis of 1-minute or 5-minute or 1-hour intervals and storing the results in an easy-to-query wide table.

I use an expression boolean variable with per minute historian and similar logic. And count True value in the time range. It's a little slow, but pretty easy.