# Pump working hours

**URL:** <https://forum.inductiveautomation.com/t/pump-working-hours/43891>\
**Category:** Ignition\
**Created:** [February 26, 2021, 8:48pm UTC](https://forum.inductiveautomation.com/t/pump-working-hours/43891 "2021-02-26T20:48:47Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 28, 2021, 2:47pm UTC](https://forum.inductiveautomation.com/t/pump-working-hours/43891/6 "2021-02-28T14:47:45Z")

</div>

> [@zarkokv](#):
>
> But, that is the same that already do historian

The historian add much indirection and, with partitioning, a variable list of tables to work with. A dedicated table can be simple, and with the use of lead()/lag() functions, easy to query for interval lengths. This post discusses the technique:

> [@Calculations based on relatime values](http://forum.inductiveautomation.com/t/calculations-based-on-relatime-values/10418/3):
>
> Adding to Al’s suggestion… When you then need to query the database for completed cycles, you can use your database’s window aggregate functions to give you the deltas. For example, in Postgres, it’d look something like this:Select t\_stamp, deltaweight From ( Select t\_stamp, weight - lead(weight) over (order by t\_stamp desc) as deltaweight From grouptable Order By t\_stamp Desc Limit 2) grouptabledelta Limit 1;Note that lead() and lag() are based on the row order involved. Since this q…

{ Note that MySQL can do window aggregates now. But I still recommend MariaDB or PostgreSQL. }

---

_[View the full topic](https://forum.inductiveautomation.com/t/pump-working-hours/43891)._
