DB Data calculation

I need to made a calculation of an average value of a flow rate taken by a database interval then I have to calculate the total product consumption in the same interval and I have no idea at all on how to create the script (activated by a button).

Any suggestion?

Thank you

Can you provide some example data to make the explination non-trivial?
Otherwise, average is the sum of the values divided by the number of values. Consumption is the average flow rate multipled by the time.
There are a few concepts to use, depending on how accurate you need the result to be. Like using milliseconds in the timestamps.
Are you wanting a moving average, or just a value between fixed times?

Thank you for replying, I’ll try to be more clear:
I have a flow rate that can be recorded every 1 or 2 seconds. This value is stored into a Database (I have prepared an historical transaction group).
I know that with “Select AVG(flowRate) From DB” I will have an average value of Flow rate of all recorded values but I have 2 things to do:

  1. Select a starting timestamp and an ending timestamp to create an average (I was thinking to use 2 calendar for this purpose) and this should not be a problem. When the interval is selected, I need to count how many records are in this interval to create the total amount of product used and this is something that I don’t know how to do it.
  2. I need to put this script in a specific window when is open, the calculation is made and is updated everytime the measure change and not only updated when the windows open or is focused.
    Thank you